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

Get a list of Routing Form Submissions for a specified Routing Form.

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

6
export async function main(
7
	auth: Calendly,
8
	form: 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_form_submissions`)
14

15
	for (const [k, v] of [
16
		['form', form],
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