0

Import 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. **Note**: - Any contact attribute that doesn't exist in your account will be ignored at import end.

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Import contacts
7
 * It returns the background process ID which on completion calls
8
the notify URL that you have set in the input.
9

10
**Note**:
11
- Any contact attribute that doesn't exist in your account will be ignored at import end.
12

13
 */
14
export async function main(
15
  auth: Brevo,
16
  body: {
17
    fileUrl?: string;
18
    fileBody?: string;
19
    jsonBody?: { email?: string; attributes?: {} }[];
20
    listIds?: number[];
21
    notifyUrl?: string;
22
    newList?: { listName?: string; folderId?: number };
23
    emailBlacklist?: false | true;
24
    disableNotification?: false | true;
25
    smsBlacklist?: false | true;
26
    updateExistingContacts?: false | true;
27
    emptyContactsAttributes?: false | true;
28
  },
29
) {
30
  const url = new URL(`https://api.brevo.com/v3/contacts/import`);
31

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