0

Export an SMS campaign's recipients

by
Published Apr 8, 2025

It returns the background process ID which on completion calls the notify URL that you have set in the input.

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Export an SMS campaign's recipients
7
 * It returns the background process ID which on completion calls the notify URL that you have set in the input.
8
 */
9
export async function main(
10
  auth: Brevo,
11
  campaignId: string,
12
  body: {
13
    notifyURL?: string;
14
    recipientsType:
15
      | "all"
16
      | "delivered"
17
      | "answered"
18
      | "softBounces"
19
      | "hardBounces"
20
      | "unsubscribed";
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.brevo.com/v3/smsCampaigns/${campaignId}/exportRecipients`,
25
  );
26

27
  const response = await fetch(url, {
28
    method: "POST",
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.json();
40
}
41