0

Get Webhooks

by
Published Apr 8, 2025

Get all webhooks in an account.*Rate limits*:Burst: `1/s`Steady: `15/m` **Scopes:** `webhooks:read`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Get Webhooks
7
 * Get all webhooks in an account.*Rate limits*:Burst: `1/s`Steady: `15/m`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  fields_webhook_: string | undefined,
13
  include: string | undefined,
14
  revision: string,
15
) {
16
  const url = new URL(`https://a.klaviyo.com/api/webhooks`);
17
  for (const [k, v] of [
18
    ["fields[webhook]", fields_webhook_],
19
    ["include", include],
20
  ]) {
21
    if (v !== undefined && v !== "" && k !== undefined) {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      revision: revision,
29
      "Accept": "application/vnd.api+json",
30
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40