0
Cancel Event
One script reply has been approved by the moderators Verified

Cancels specified event.

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(auth: Calendly, uuid: string, body: { reason?: string }) {
7
	const url = new URL(`https://api.calendly.com/scheduled_events/${uuid}/cancellation`)
8

9
	const formData = new FormData()
10

11
	for (const [k, v] of Object.entries(body)) {
12
		if (v !== undefined && v !== '') {
13
			formData.append(k, String(v))
14
		}
15
	}
16

17
	const response = await fetch(url, {
18
		method: 'POST',
19
		headers: {
20
			'Content-Type': 'application/json',
21
			Authorization: 'Bearer ' + auth.token
22
		},
23
		body: JSON.stringify(body)
24
	})
25

26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30

31
	return await response.json()
32
}
33