0

Export contacts

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. File will be available in csv.

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 contacts
7
 * It returns the background process ID which on completion calls the notify URL that you have set in the input. File will be available in csv.
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    exportAttributes?: string[];
13
    customContactFilter: {
14
      actionForContacts?:
15
        | "allContacts"
16
        | "subscribed"
17
        | "unsubscribed"
18
        | "unsubscribedPerList";
19
      actionForEmailCampaigns?:
20
        | "unsubscribed"
21
        | "openers"
22
        | "nonOpeners"
23
        | "clickers"
24
        | "nonClickers"
25
        | "hardBounces"
26
        | "softBounces";
27
      actionForSmsCampaigns?: "unsubscribed" | "hardBounces" | "softBounces";
28
      listId?: number;
29
      emailCampaignId?: number;
30
      smsCampaignId?: number;
31
    };
32
    notifyUrl?: string;
33
  },
34
) {
35
  const url = new URL(`https://api.brevo.com/v3/contacts/export`);
36

37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      "api-key": auth.apiKey,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51