0
Create Webhook Subscription
One script reply has been approved by the moderators Verified

Create a Webhook Subscription for an Organization or User.

Created by hugo697 51 days ago Viewed 576 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
	body: {
9
		url: string
10
		events:
11
			| 'invitee.canceled'
12
			| 'invitee.created'
13
			| 'invitee_no_show.created'
14
			| 'invitee_no_show.deleted'
15
			| 'routing_form_submission.created'[]
16
		organization: string
17
		user?: string
18
		group?: string
19
		scope: 'organization' | 'user' | 'group'
20
		signing_key?: string
21
	}
22
) {
23
	const url = new URL(`https://api.calendly.com/webhook_subscriptions`)
24

25
	const response = await fetch(url, {
26
		method: 'POST',
27
		headers: {
28
			'Content-Type': 'application/json',
29
			Authorization: 'Bearer ' + auth.token
30
		},
31
		body: JSON.stringify(body)
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