1 | |
2 | type Brevo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create a task |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Brevo, |
11 | body: { |
12 | name: string; |
13 | duration?: number; |
14 | taskTypeId: string; |
15 | date: string; |
16 | notes?: string; |
17 | done?: false | true; |
18 | assignToId?: string; |
19 | contactsIds?: number[]; |
20 | dealsIds?: string[]; |
21 | companiesIds?: string[]; |
22 | reminder?: { |
23 | value: number; |
24 | unit: "minutes" | "hours" | "weeks" | "days"; |
25 | types: "email" | "push"[]; |
26 | }; |
27 | }, |
28 | ) { |
29 | const url = new URL(`https://api.brevo.com/v3/crm/tasks`); |
30 |
|
31 | const response = await fetch(url, { |
32 | method: "POST", |
33 | headers: { |
34 | "Content-Type": "application/json", |
35 | "api-key": auth.apiKey, |
36 | }, |
37 | body: JSON.stringify(body), |
38 | }); |
39 | if (!response.ok) { |
40 | const text = await response.text(); |
41 | throw new Error(`${response.status} ${text}`); |
42 | } |
43 | return await response.json(); |
44 | } |
45 |
|