0

Get the list of all the events for the received emails.

by
Published Apr 8, 2025

This endpoint will show the list of all the events for the received emails.

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Get the list of all the events for the received emails.
7
 * This endpoint will show the list of all the events for the received emails.
8
 */
9
export async function main(
10
  auth: Brevo,
11
  sender: string | undefined,
12
  startDate: string | undefined,
13
  endDate: string | undefined,
14
  limit: string | undefined,
15
  offset: string | undefined,
16
  sort: "asc" | "desc" | undefined,
17
) {
18
  const url = new URL(`https://api.brevo.com/v3/inbound/events`);
19
  for (const [k, v] of [
20
    ["sender", sender],
21
    ["startDate", startDate],
22
    ["endDate", endDate],
23
    ["limit", limit],
24
    ["offset", offset],
25
    ["sort", sort],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      "api-key": auth.apiKey,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44