0

Create a company/deal 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
 * Create a company/deal attribute
7
 *
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    label: string;
13
    attributeType:
14
      | "number"
15
      | "boolean"
16
      | "text"
17
      | "user"
18
      | "single-select"
19
      | "date"
20
      | "multi-choice";
21
    description?: string;
22
    optionsLabels?: string[];
23
    objectType: "companies" | "deals";
24
  },
25
) {
26
  const url = new URL(`https://api.brevo.com/v3/crm/attributes`);
27

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