// Requires apiVersion 202311 or lower.
type Linkedin = {
token: string
apiVersion: string
}
export async function main(
resource: Linkedin,
searchBy: 'vanity' | 'email',
searchQuery: string, // must be either vanity name or email domain
maxResults: number = 100
) {
const count = 50 // Number of results per request
const results: any[] = []
const params = new URLSearchParams()
if (searchBy === 'vanity') {
params.append('q', 'vanityName')
params.append('vanityName', searchQuery)
} else {
params.append('q', 'emailDomain')
params.append('emailDomain', searchQuery)
}
params.append('count', count.toString())
params.append('start', '0')
let done = false
do {
const endpoint = `https://api.linkedin.com/rest/organizations?${params.toString()}`
const response = await fetch(endpoint, {
method: 'GET',
headers: {
Authorization: `Bearer ${resource.token}`,
'LinkedIn-Version': `${resource.apiVersion}`,
'X-Restli-Protocol-Version': '2.0.0'
}
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
results.push(...data.elements)
params.set('start', (parseInt(params.get('start')!) + count).toString())
if (data.elements.length < count || results.length >= maxResults) {
done = true
}
} while (!done)
return results.slice(0, maxResults)
}
Submitted by hugo697 130 days ago
// Requires apiVersion 202311 or lower.
type Linkedin = {
token: string
apiVersion: string
}
export async function main(
resource: Linkedin,
searchBy: 'vanity' | 'email',
searchQuery: string, // must be either vanity name or email domain
maxResults: number = 100
) {
const count = 50 // Number of results per request
const results: any[] = []
const params = new URLSearchParams()
if (searchBy === 'vanity') {
params.append('q', 'vanityName')
params.append('vanityName', searchQuery)
} else {
params.append('q', 'emailDomain')
params.append('emailDomain', searchQuery)
}
params.append('count', count.toString())
params.append('start', '0')
let done = false
do {
const endpoint = `https://api.linkedin.com/rest/organizations?${params.toString()}`
const response = await fetch(endpoint, {
method: 'GET',
headers: {
Authorization: `Bearer ${resource.token}`,
'LinkedIn-Version': `${resource.apiVersion}`,
'X-Restli-Protocol-Version': '2.0.0'
}
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
results.push(...data.elements)
params.set('start', (parseInt(params.get('start')!) + count).toString())
if (data.elements.length < count || results.length >= maxResults) {
done = true
}
} while (!done)
return results.slice(0, maxResults)
}
Submitted by hugo697 130 days ago