0

Create an event

by
Published Apr 8, 2025

Create an event to track a contact's interaction.

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 an event
7
 * Create an event to track a contact's interaction.
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    event_name: string;
13
    event_date?: string;
14
    identifiers: {
15
      email_id?: string;
16
      phone_id?: string;
17
      whatsapp_id?: string;
18
      landline_number_id?: string;
19
      ext_id?: string;
20
    };
21
    contact_properties?: {};
22
    event_properties?: {};
23
  },
24
) {
25
  const url = new URL(`https://api.brevo.com/v3/events`);
26

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