0
List User Availability Schedules
One script reply has been approved by the moderators Verified

Returns the availability schedules of the given user.

Created by hugo697 51 days ago Viewed 575 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(auth: Calendly, user: string | undefined) {
7
	const url = new URL(`https://api.calendly.com/user_availability_schedules`)
8

9
	for (const [k, v] of [['user', user]]) {
10
		if (v !== undefined && v !== '' && k !== undefined) {
11
			url.searchParams.append(k, v)
12
		}
13
	}
14

15
	const response = await fetch(url, {
16
		method: 'GET',
17
		headers: {
18
			Authorization: 'Bearer ' + auth.token
19
		},
20
		body: undefined
21
	})
22

23
	if (!response.ok) {
24
		const text = await response.text()
25
		throw new Error(`${response.status} ${text}`)
26
	}
27

28
	return await response.json()
29
}
30