0
List Event Type Hosts
One script reply has been approved by the moderators Verified

Fetch list of event type hosts

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
	event_type: string | undefined,
9
	count: string | undefined,
10
	page_token: string | undefined
11
) {
12
	const url = new URL(`https://api.calendly.com/event_type_memberships`)
13

14
	for (const [k, v] of [
15
		['event_type', event_type],
16
		['count', count],
17
		['page_token', page_token]
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