0

Get Tracking Setting

by
Published Apr 8, 2025

Get the tracking setting with the given account ID.*Rate limits*:Burst: `10/s`Steady: `150/m` **Scopes:** `tracking-settings: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 Tracking Setting
7
 * Get the tracking setting with the given account ID.*Rate limits*:Burst: `10/s`Steady: `150/m`
8

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