0

Update a webhook

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
 * Update a webhook
7
 *
8
 */
9
export async function main(
10
  auth: Brevo,
11
  webhookId: string,
12
  body: {
13
    url?: string;
14
    description?: string;
15
    events?:
16
      | "sent"
17
      | "hardBounce"
18
      | "softBounce"
19
      | "blocked"
20
      | "spam"
21
      | "delivered"
22
      | "request"
23
      | "click"
24
      | "invalid"
25
      | "deferred"
26
      | "opened"
27
      | "uniqueOpened"
28
      | "unsubscribed"
29
      | "listAddition"
30
      | "contactUpdated"
31
      | "contactDeleted"
32
      | "inboundEmailProcessed"[];
33
    domain?: string;
34
    batched?: false | true;
35
    auth?: {};
36
    headers?: {}[];
37
  },
38
) {
39
  const url = new URL(`https://api.brevo.com/v3/webhooks/${webhookId}`);
40

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