1 | |
2 | type Brevo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update an email campaign |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Brevo, |
11 | campaignId: string, |
12 | body: { |
13 | tag?: string; |
14 | sender?: { name?: string; email?: string; id?: number }; |
15 | name?: string; |
16 | htmlContent?: string; |
17 | htmlUrl?: string; |
18 | scheduledAt?: string; |
19 | subject?: string; |
20 | previewText?: string; |
21 | replyTo?: string; |
22 | toField?: string; |
23 | recipients?: { |
24 | exclusionListIds?: number[]; |
25 | listIds?: number[]; |
26 | segmentIds?: number[]; |
27 | }; |
28 | attachmentUrl?: string; |
29 | inlineImageActivation?: false | true; |
30 | mirrorActive?: false | true; |
31 | recurring?: false | true; |
32 | footer?: string; |
33 | header?: string; |
34 | utmCampaign?: string; |
35 | params?: {}; |
36 | sendAtBestTime?: false | true; |
37 | abTesting?: false | true; |
38 | subjectA?: string; |
39 | subjectB?: string; |
40 | splitRule?: number; |
41 | winnerCriteria?: "open" | "click"; |
42 | winnerDelay?: number; |
43 | ipWarmupEnable?: false | true; |
44 | initialQuota?: number; |
45 | increaseRate?: number; |
46 | unsubscriptionPageId?: string; |
47 | updateFormId?: string; |
48 | emailExpirationDate?: { |
49 | duration?: number; |
50 | unit?: "days" | "weeks" | "months"; |
51 | }; |
52 | }, |
53 | ) { |
54 | const url = new URL(`https://api.brevo.com/v3/emailCampaigns/${campaignId}`); |
55 |
|
56 | const response = await fetch(url, { |
57 | method: "PUT", |
58 | headers: { |
59 | "Content-Type": "application/json", |
60 | "api-key": auth.apiKey, |
61 | }, |
62 | body: JSON.stringify(body), |
63 | }); |
64 | if (!response.ok) { |
65 | const text = await response.text(); |
66 | throw new Error(`${response.status} ${text}`); |
67 | } |
68 | return await response.text(); |
69 | } |
70 |
|