1 | |
2 | type Brevo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Export the recipients of an email campaign |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Brevo, |
11 | campaignId: string, |
12 | body: { |
13 | notifyURL?: string; |
14 | recipientsType: |
15 | | "all" |
16 | | "nonClickers" |
17 | | "nonOpeners" |
18 | | "clickers" |
19 | | "openers" |
20 | | "softBounces" |
21 | | "hardBounces" |
22 | | "unsubscribed"; |
23 | }, |
24 | ) { |
25 | const url = new URL( |
26 | `https://api.brevo.com/v3/emailCampaigns/${campaignId}/exportRecipients`, |
27 | ); |
28 |
|
29 | const response = await fetch(url, { |
30 | method: "POST", |
31 | headers: { |
32 | "Content-Type": "application/json", |
33 | "api-key": auth.apiKey, |
34 | }, |
35 | body: JSON.stringify(body), |
36 | }); |
37 | if (!response.ok) { |
38 | const text = await response.text(); |
39 | throw new Error(`${response.status} ${text}`); |
40 | } |
41 | return await response.json(); |
42 | } |
43 |
|