0
List Organization Memberships
One script reply has been approved by the moderators Verified

Use this to list the Organization Memberships for all users belonging to an organization, use:

  • user to look up a user's membership in an organization
  • organization to look up all users that belong to the organization

This endpoint can also be used to retrieve your organization URI.

Created by hugo697 52 days ago Viewed 599 times
0
Submitted by hugo697 Bun
Verified 52 days ago
1
//native
2
type Calendly = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Calendly,
8
	page_token: string | undefined,
9
	count: string | undefined,
10
	email: string | undefined,
11
	organization: string | undefined,
12
	user: string | undefined
13
) {
14
	const url = new URL(`https://api.calendly.com/organization_memberships`)
15
	for (const [k, v] of [
16
		['page_token', page_token],
17
		['count', count],
18
		['email', email],
19
		['organization', organization],
20
		['user', user]
21
	]) {
22
		if (v !== undefined && v !== '' && k !== undefined) {
23
			url.searchParams.append(k, v)
24
		}
25
	}
26

27
	const response = await fetch(url, {
28
		method: 'GET',
29
		headers: {
30
			Authorization: 'Bearer ' + auth.token
31
		},
32
		body: undefined
33
	})
34

35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39

40
	return await response.json()
41
}
42