0

Export all webhook events

by
Published Apr 8, 2025

This endpoint will submit a request to get the history of webhooks in the CSV file. The link to download the CSV file will be sent to the webhook that was provided in the notifyURL.

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Export all webhook events
7
 * This endpoint will submit a request to get the history of webhooks in the CSV file. The link to download the CSV file will be sent to the webhook that was provided in the notifyURL.
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    days?: number;
13
    startDate?: string;
14
    endDate?: string;
15
    sort?: string;
16
    type: "transactional" | "marketing";
17
    event:
18
      | "invalid_parameter"
19
      | "missing_parameter"
20
      | "hardBounce"
21
      | "softBounce"
22
      | "delivered"
23
      | "spam"
24
      | "request"
25
      | "opened"
26
      | "click"
27
      | "invalid"
28
      | "deferred"
29
      | "blocked"
30
      | "unsubscribed"
31
      | "error"
32
      | "uniqueOpened"
33
      | "loadedByProxy"
34
      | "allEvents";
35
    notifyURL: string;
36
    webhookId?: number;
37
    email?: string;
38
    messageId?: number;
39
  },
40
) {
41
  const url = new URL(`https://api.brevo.com/v3/webhooks/export`);
42

43
  const response = await fetch(url, {
44
    method: "POST",
45
    headers: {
46
      "Content-Type": "application/json",
47
      "api-key": auth.apiKey,
48
    },
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57