1 | |
2 | type Holded = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create booking |
7 | * Create new booking. |
8 | */ |
9 | export async function main( |
10 | auth: Holded, |
11 | body: { |
12 | locationId: string; |
13 | serviceId: string; |
14 | dateTime: number; |
15 | timezone: string; |
16 | language: string; |
17 | customFields: { key?: string; value?: string }[]; |
18 | }, |
19 | ) { |
20 | const url = new URL(`https://api.holded.com/api/crm/v1/bookings`); |
21 |
|
22 | const response = await fetch(url, { |
23 | method: "POST", |
24 | headers: { |
25 | "Content-Type": "application/json", |
26 | key: auth.apiKey, |
27 | }, |
28 | body: JSON.stringify(body), |
29 | }); |
30 | if (!response.ok) { |
31 | const text = await response.text(); |
32 | throw new Error(`${response.status} ${text}`); |
33 | } |
34 | return await response.json(); |
35 | } |
36 |
|