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

Returns a list of groups.

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

6
export async function main(
7
	auth: Calendly,
8
	organization: string | undefined,
9
	page_token: string | undefined,
10
	count: string | undefined
11
) {
12
	const url = new URL(`https://api.calendly.com/groups`)
13

14
	for (const [k, v] of [
15
		['organization', organization],
16
		['page_token', page_token],
17
		['count', count]
18
	]) {
19
		if (v !== undefined && v !== '' && k !== undefined) {
20
			url.searchParams.append(k, v)
21
		}
22
	}
23

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

32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36

37
	return await response.json()
38
}
39