1 | |
2 | type Calendly = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Calendly, |
8 | organization: string | undefined, |
9 | user: string | undefined, |
10 | group: string | undefined, |
11 | page_token: string | undefined, |
12 | count: string | undefined, |
13 | sort: string | undefined, |
14 | scope: 'organization' | 'user' | 'group' | undefined |
15 | ) { |
16 | const url = new URL(`https://api.calendly.com/webhook_subscriptions`) |
17 |
|
18 | for (const [k, v] of [ |
19 | ['organization', organization], |
20 | ['user', user], |
21 | ['group', group], |
22 | ['page_token', page_token], |
23 | ['count', count], |
24 | ['sort', sort], |
25 | ['scope', scope] |
26 | ]) { |
27 | if (v !== undefined && v !== '' && k !== undefined) { |
28 | url.searchParams.append(k, v) |
29 | } |
30 | } |
31 |
|
32 | const response = await fetch(url, { |
33 | method: 'GET', |
34 | headers: { |
35 | Authorization: 'Bearer ' + auth.token |
36 | }, |
37 | body: undefined |
38 | }) |
39 |
|
40 | if (!response.ok) { |
41 | const text = await response.text() |
42 | throw new Error(`${response.status} ${text}`) |
43 | } |
44 |
|
45 | return await response.json() |
46 | } |
47 |
|