1 | |
2 | type Brevo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update an email campaign status |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Brevo, |
11 | campaignId: string, |
12 | body: { |
13 | status?: |
14 | | "suspended" |
15 | | "archive" |
16 | | "darchive" |
17 | | "sent" |
18 | | "queued" |
19 | | "replicate" |
20 | | "replicateTemplate" |
21 | | "draft"; |
22 | }, |
23 | ) { |
24 | const url = new URL( |
25 | `https://api.brevo.com/v3/emailCampaigns/${campaignId}/status`, |
26 | ); |
27 |
|
28 | const response = await fetch(url, { |
29 | method: "PUT", |
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 |
|