1 | |
2 | type Calendly = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Calendly, |
8 | body: { |
9 | name: string |
10 | host: string |
11 | co_hosts?: string[] |
12 | duration: number |
13 | timezone?: string |
14 | date_setting: |
15 | | { type: 'date_range'; start_date: string; end_date: string } |
16 | | { type: 'days_in_future'; days: number; only_weekdays: false | true } |
17 | | {} |
18 | location?: |
19 | | { kind: 'custom'; location?: string } |
20 | | { kind: 'google_conference' } |
21 | | { kind: 'gotomeeting_conference' } |
22 | | { kind: 'physical'; location?: string; additional_info?: string } |
23 | | { kind: 'inbound_call'; phone_number: string; additional_info?: string } |
24 | | { kind: 'ask_invitee'; location?: string } |
25 | | { kind: 'microsoft_teams_conference' } |
26 | | { kind: 'outbound_call' } |
27 | | { kind: 'webex_conference' } |
28 | | { kind: 'zoom_conference' } |
29 | } |
30 | ) { |
31 | const url = new URL(`https://api.calendly.com/one_off_event_types`) |
32 |
|
33 | const response = await fetch(url, { |
34 | method: 'POST', |
35 | headers: { |
36 | 'Content-Type': 'application/json', |
37 | Authorization: 'Bearer ' + auth.token |
38 | }, |
39 | body: JSON.stringify(body) |
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 |
|