0

Delete a contact from a list

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
 * Delete a contact from a list
7
 *
8
 */
9
export async function main(
10
  auth: Brevo,
11
  listId: string,
12
  body:
13
    | { emails?: string[] }
14
    | { ids?: number[] }
15
    | { all?: false | true }
16
    | { extIds?: string[] },
17
) {
18
  const url = new URL(
19
    `https://api.brevo.com/v3/contacts/lists/${listId}/contacts/remove`,
20
  );
21

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