0
Gets Organization Access Control
One script reply has been approved by the moderators Verified

Gets an organization's access control information, given the organization urn. See the docs here

Created by hugo697 140 days ago Viewed 52 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 140 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
		count: count.toString(),
13
		start: '0'
14
	})
15

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

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

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

33
		const data = await response.json()
34
		results.push(...data.elements)
35

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

42
	return results.slice(0, maxResults)
43
}
44