type Linkedin = {
token: string
apiVersion: string
}
export async function main(resource: Linkedin, organizationUrn: string, maxResults: number = 100) {
const count = 50 // Number of results per request
const results: any[] = []
let params = new URLSearchParams({
q: 'organization',
organization: encodeURIComponent(organizationUrn),
count: count.toString(),
start: '0'
})
let done = false
do {
const endpoint = `https://api.linkedin.com/rest/organizationAcls?${params.toString()}`
const response = await fetch(endpoint, {
method: 'GET',
headers: {
Authorization: `Bearer ${resource.token}`,
'X-Restli-Protocol-Version': '2.0.0',
'LinkedIn-Version': `${resource.apiVersion}`
}
})
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 140 days ago
type Linkedin = {
token: string
apiVersion: string
}
export async function main(resource: Linkedin, organizationUrn: string, maxResults: number = 100) {
const count = 50 // Number of results per request
const results: any[] = []
let params = new URLSearchParams({
q: 'organization',
organization: encodeURIComponent(organizationUrn),
count: count.toString(),
start: '0'
})
let done = false
do {
const endpoint = `https://api.linkedin.com/rest/organizationAcls?${params.toString()}`
const response = await fetch(endpoint, {
method: 'GET',
headers: {
Authorization: `Bearer ${resource.token}`,
'X-Restli-Protocol-Version': '2.0.0',
'LinkedIn-Version': `${resource.apiVersion}`
}
})
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 140 days ago