1 | |
2 | type Brevo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update multiple contacts |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Brevo, |
11 | body: { |
12 | contacts?: { |
13 | email?: string; |
14 | id?: number; |
15 | sms?: string; |
16 | ext_id?: string; |
17 | attributes?: {}; |
18 | emailBlacklisted?: false | true; |
19 | smsBlacklisted?: false | true; |
20 | listIds?: number[]; |
21 | unlinkListIds?: number[]; |
22 | smtpBlacklistSender?: string[]; |
23 | }[]; |
24 | }, |
25 | ) { |
26 | const url = new URL(`https://api.brevo.com/v3/contacts/batch`); |
27 |
|
28 | const response = await fetch(url, { |
29 | method: "POST", |
30 | headers: { |
31 | "Content-Type": "application/json", |
32 | "api-key": auth.apiKey, |
33 | }, |
34 | body: JSON.stringify(body), |
35 | }); |
36 | if (!response.ok) { |
37 | const text = await response.text(); |
38 | throw new Error(`${response.status} ${text}`); |
39 | } |
40 | return await response.text(); |
41 | } |
42 |
|