0

Update Webhook

by
Published Apr 8, 2025

Update the webhook with the given ID.*Rate limits*:Burst: `1/s`Steady: `15/m` **Scopes:** `webhooks:write`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Update Webhook
7
 * Update the webhook with the given ID.*Rate limits*:Burst: `1/s`Steady: `15/m`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  id: string,
13
  revision: string,
14
  body: {
15
    data: {
16
      type: "webhook";
17
      id: string;
18
      attributes: {
19
        name?: string;
20
        description?: string;
21
        endpoint_url?: string;
22
        secret_key?: string;
23
        enabled?: false | true;
24
      };
25
      relationships?: {
26
        "webhook-topics"?: { data?: { type: "webhook-topic"; id: string }[] };
27
      };
28
    };
29
  },
30
) {
31
  const url = new URL(`https://a.klaviyo.com/api/webhooks/${id}`);
32

33
  const response = await fetch(url, {
34
    method: "PATCH",
35
    headers: {
36
      revision: revision,
37
      "Accept": "application/vnd.api+json",
38
      "Content-Type": "application/vnd.api+json",
39
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49