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