0

Update a WhatsApp campaign

by
Published Apr 8, 2025
Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Update a WhatsApp campaign
7
 *
8
 */
9
export async function main(
10
  auth: Brevo,
11
  campaignId: string,
12
  body: {
13
    campaignName?: string;
14
    campaignStatus?: "scheduled" | "suspended";
15
    rescheduleFor?: string;
16
    recipients?: {
17
      excludedListIds?: number[];
18
      listIds?: number[];
19
      segments?: number[];
20
    };
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.brevo.com/v3/whatsappCampaigns/${campaignId}`,
25
  );
26

27
  const response = await fetch(url, {
28
    method: "PUT",
29
    headers: {
30
      "Content-Type": "application/json",
31
      "api-key": auth.apiKey,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.text();
40
}
41