Get Organization Administrators

Gets the administator members of an organization, given the organization urn. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/organizations/organization-access-control?context=linkedin/compliance/context#find-organization-administrators)

Script linkedin Verified

by hugo697 ยท 7/17/2024

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 689 days ago
1
type Linkedin = {
2
	token: string
3
	apiVersion: string
4
}
5

6
export async function main(resource: Linkedin, organizationUrn: string, maxResults: number = 100) {
7
	const count = 50 // Number of results per request
8
	const results: any[] = []
9
	let params = new URLSearchParams({
10
		q: 'organization',
11
		organization: encodeURIComponent(organizationUrn),
12
		role: 'ADMINISTRATOR',
13
		state: 'APPROVED',
14
		count: count.toString(),
15
		start: '0'
16
	})
17

18
	let done = false
19
	do {
20
		const endpoint = `https://api.linkedin.com/rest/organizationAcls?${params.toString()}`
21

22
		const response = await fetch(endpoint, {
23
			method: 'GET',
24
			headers: {
25
				Authorization: `Bearer ${resource.token}`,
26
				'X-Restli-Protocol-Version': '2.0.0',
27
				'LinkedIn-Version': `${resource.apiVersion}`
28
			}
29
		})
30

31
		if (!response.ok) {
32
			throw new Error(`HTTP error! status: ${response.status}`)
33
		}
34

35
		const data = await response.json()
36
		results.push(...data.elements)
37

38
		params.set('start', (parseInt(params.get('start')!) + count).toString())
39
		if (data.elements.length < count || results.length >= maxResults) {
40
			done = true
41
		}
42
	} while (!done)
43

44
	return results.slice(0, maxResults)
45
}
46