0
Get Member's Organization Access Control Information
One script reply has been approved by the moderators Verified

Gets the organization access control information of the current authenticated member. See the docs here

Created by hugo697 129 days ago Viewed 49 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 129 days ago
1
type Linkedin = {
2
	token: string
3
	apiVersion: string
4
}
5

6
export async function main(
7
	resource: Linkedin,
8
	maxResults: number = 100,
9
	role?: string,
10
	state?: string
11
) {
12
	const count = 50 // Number of results per request
13
	const results: any[] = []
14

15
	let params = new URLSearchParams({
16
		q: 'roleAssignee',
17
		count: count.toString(),
18
		start: '0'
19
	})
20

21
	// Add role and state to params if they are defined
22
	if (role) {
23
		params.append('role', role)
24
	}
25
	if (state) {
26
		params.append('state', state)
27
	}
28

29
	let done = false
30
	do {
31
		const endpoint = `https://api.linkedin.com/rest/organizationAcls?${params.toString()}`
32

33
		const response = await fetch(endpoint, {
34
			method: 'GET',
35
			headers: {
36
				Authorization: `Bearer ${resource.token}`,
37
				'X-Restli-Protocol-Version': '2.0.0',
38
				'LinkedIn-Version': `${resource.apiVersion}`
39
			}
40
		})
41

42
		if (!response.ok) {
43
			throw new Error(`HTTP error! status: ${response.status}`)
44
		}
45

46
		const data = await response.json()
47
		results.push(...data.elements)
48

49
		params.set('start', (parseInt(params.get('start')!) + count).toString())
50
		if (data.elements.length < count || results.length >= maxResults) {
51
			done = true
52
		}
53
	} while (!done)
54

55
	return results.slice(0, maxResults)
56
}
57