1 | |
2 | type Brevo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update an SMS campaign |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Brevo, |
11 | campaignId: string, |
12 | body: { |
13 | name?: string; |
14 | sender?: string; |
15 | content?: string; |
16 | recipients?: { listIds: number[]; exclusionListIds?: number[] }; |
17 | scheduledAt?: string; |
18 | unicodeEnabled?: false | true; |
19 | organisationPrefix?: string; |
20 | unsubscribeInstruction?: string; |
21 | }, |
22 | ) { |
23 | const url = new URL(`https://api.brevo.com/v3/smsCampaigns/${campaignId}`); |
24 |
|
25 | const response = await fetch(url, { |
26 | method: "PUT", |
27 | headers: { |
28 | "Content-Type": "application/json", |
29 | "api-key": auth.apiKey, |
30 | }, |
31 | body: JSON.stringify(body), |
32 | }); |
33 | if (!response.ok) { |
34 | const text = await response.text(); |
35 | throw new Error(`${response.status} ${text}`); |
36 | } |
37 | return await response.text(); |
38 | } |
39 |
|