List User's Event Types
One script reply has been approved by the moderators Verified

Returns all Event Types associated with a specified User. Use:

  • organization to look up all Event Types that belong to the organization
  • user to look up a user's Event Types in an organization

Either organization or user are required query params when using this endpoint.

Created by hugo697 403 days ago
Submitted by hugo697 Bun
Verified 403 days ago
1
//native
2
type Calendly = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Calendly,
8
	active: string | undefined,
9
	organization: string | undefined,
10
	user: string | undefined,
11
	user_availability_schedule: string | undefined,
12
	sort: string | undefined,
13
	admin_managed: string | undefined,
14
	page_token: string | undefined,
15
	count: string | undefined
16
) {
17
	const url = new URL(`https://api.calendly.com/event_types`)
18

19
	for (const [k, v] of [
20
		['active', active],
21
		['organization', organization],
22
		['user', user],
23
		['user_availability_schedule', user_availability_schedule],
24
		['sort', sort],
25
		['admin_managed', admin_managed],
26
		['page_token', page_token],
27
		['count', count]
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