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

Returns a list of Organization Invitations that were sent to the organization's members.

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

6
export async function main(
7
	auth: Calendly,
8
	uuid: string,
9
	count: string | undefined,
10
	page_token: string | undefined,
11
	sort: string | undefined,
12
	email: string | undefined,
13
	status: 'pending' | 'accepted' | 'declined' | undefined
14
) {
15
	const url = new URL(`https://api.calendly.com/organizations/${uuid}/invitations`)
16

17
	for (const [k, v] of [
18
		['count', count],
19
		['page_token', page_token],
20
		['sort', sort],
21
		['email', email],
22
		['status', status]
23
	]) {
24
		if (v !== undefined && v !== '' && k !== undefined) {
25
			url.searchParams.append(k, v)
26
		}
27
	}
28

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

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

42
	return await response.json()
43
}
44