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

Get a list of Routing Forms for a specified Organization.

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

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

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

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

39
	return await response.json()
40
}
41