type Linkedin = {
token: string
apiVersion: string
}
export async function main(
resource: Linkedin,
maxResults: number = 100,
role?: string,
state?: string
) {
const count = 50 // Number of results per request
const results: any[] = []
let params = new URLSearchParams({
q: 'roleAssignee',
count: count.toString(),
start: '0'
})
// Add role and state to params if they are defined
if (role) {
params.append('role', role)
}
if (state) {
params.append('state', state)
}
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 129 days ago
type Linkedin = {
token: string
apiVersion: string
}
export async function main(
resource: Linkedin,
maxResults: number = 100,
role?: string,
state?: string
) {
const count = 50 // Number of results per request
const results: any[] = []
let params = new URLSearchParams({
q: 'roleAssignee',
count: count.toString(),
start: '0'
})
// Add role and state to params if they are defined
if (role) {
params.append('role', role)
}
if (state) {
params.append('state', state)
}
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 130 days ago