0

Delete an attribute

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 an attribute
7
 *
8
 */
9
export async function main(
10
  auth: Brevo,
11
  attributeCategory:
12
    | "normal"
13
    | "transactional"
14
    | "category"
15
    | "calculated"
16
    | "global",
17
  attributeName: string,
18
) {
19
  const url = new URL(
20
    `https://api.brevo.com/v3/contacts/attributes/${attributeCategory}/${attributeName}`,
21
  );
22

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