1 | |
2 |
|
3 | |
4 | * Book Meeting on Meeting Link |
5 | * Book a slot on a scheduling page for a contact. `start_time` is ISO 8601 and must be an open slot (see Get Meeting Link Availability); `duration_minutes` must be one of the page's durations. Requires scheduler.meetings.meeting-link.read and write access to the scheduler. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Hubspot, |
9 | slug: string, |
10 | first_name: string, |
11 | last_name: string, |
12 | email: string, |
13 | start_time: string, |
14 | duration_minutes: number, |
15 | timezone: string, |
16 | locale: string | undefined, |
17 | guest_emails: string[] | undefined |
18 | ) { |
19 | const url = new URL( |
20 | "https://api.hubapi.com/scheduler/v3/meetings/meeting-links/book" |
21 | ) |
22 | url.searchParams.append("timezone", timezone) |
23 |
|
24 | const body: { [key: string]: any } = { |
25 | slug, |
26 | firstName: first_name, |
27 | lastName: last_name, |
28 | email, |
29 | startTime: new Date(start_time).getTime(), |
30 | duration: duration_minutes * 60000, |
31 | timezone, |
32 | } |
33 | if (locale != null && locale !== "") body.locale = locale |
34 | if (guest_emails?.length) body.guestEmails = guest_emails |
35 |
|
36 | const response = await fetch(url, { |
37 | method: "POST", |
38 | headers: { |
39 | Authorization: `Bearer ${auth.token}`, |
40 | "Content-Type": "application/json", |
41 | Accept: "application/json", |
42 | }, |
43 | body: JSON.stringify(body), |
44 | }) |
45 |
|
46 | if (!response.ok) { |
47 | throw new Error(`${response.status} ${await response.text()}`) |
48 | } |
49 |
|
50 | return await response.json() |
51 | } |
52 |
|