0
List Outgoing Communications
One script reply has been approved by the moderators Verified

This endpoint requires an Enterprise subscription. Returns a list of outgoing SMS communications.

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(
7
	auth: Calendly,
8
	organization: string | undefined,
9
	count: string | undefined,
10
	min_created_at: string | undefined,
11
	max_created_at: string | undefined,
12
	page_token: string | undefined
13
) {
14
	const url = new URL(`https://api.calendly.com/outgoing_communications`)
15

16
	for (const [k, v] of [
17
		['organization', organization],
18
		['count', count],
19
		['min_created_at', min_created_at],
20
		['max_created_at', max_created_at],
21
		['page_token', page_token]
22
	]) {
23
		if (v !== undefined && v !== '' && k !== undefined) {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27

28
	const response = await fetch(url, {
29
		method: 'GET',
30
		headers: {
31
			Authorization: 'Bearer ' + auth.token
32
		},
33
		body: undefined
34
	})
35

36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40

41
	return await response.json()
42
}
43