0
Get Sample Webhook Data
One script reply has been approved by the moderators Verified

Test your webhook subscription

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

6
export async function main(
7
	auth: Calendly,
8
	event:
9
		| 'invitee.created'
10
		| 'invitee.canceled'
11
		| 'invitee_no_show.created'
12
		| 'invitee_no_show.deleted'
13
		| 'routing_form_submission.created'
14
		| undefined,
15
	organization: string | undefined,
16
	user: string | undefined,
17
	scope: 'user' | 'organization' | 'group' | undefined,
18
	group: string | undefined
19
) {
20
	const url = new URL(`https://api.calendly.com/sample_webhook_data`)
21

22
	for (const [k, v] of [
23
		['event', event],
24
		['organization', organization],
25
		['user', user],
26
		['scope', scope],
27
		['group', group]
28
	]) {
29
		if (v !== undefined && v !== '' && k !== undefined) {
30
			url.searchParams.append(k, v)
31
		}
32
	}
33

34
	const response = await fetch(url, {
35
		method: 'GET',
36
		headers: {
37
			Authorization: 'Bearer ' + auth.token
38
		},
39
		body: undefined
40
	})
41

42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46

47
	return await response.json()
48
}
49