0

Get All Universal Content

by
Published Apr 8, 2025

Get all universal content in an account.*Rate limits*:Burst: `10/s`Steady: `150/m` **Scopes:** `templates: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 All Universal Content
7
 * Get all universal content in an account.*Rate limits*:Burst: `10/s`Steady: `150/m`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  fields_template_universal_content_: string | undefined,
13
  filter: string | undefined,
14
  page_cursor_: string | undefined,
15
  page_size_: string | undefined,
16
  sort:
17
    | "created"
18
    | "-created"
19
    | "id"
20
    | "-id"
21
    | "name"
22
    | "-name"
23
    | "updated"
24
    | "-updated"
25
    | undefined,
26
  revision: string,
27
) {
28
  const url = new URL(`https://a.klaviyo.com/api/template-universal-content`);
29
  for (const [k, v] of [
30
    ["fields[template-universal-content]", fields_template_universal_content_],
31
    ["filter", filter],
32
    ["page[cursor]", page_cursor_],
33
    ["page[size]", page_size_],
34
    ["sort", sort],
35
  ]) {
36
    if (v !== undefined && v !== "" && k !== undefined) {
37
      url.searchParams.append(k, v);
38
    }
39
  }
40
  const response = await fetch(url, {
41
    method: "GET",
42
    headers: {
43
      revision: revision,
44
      "Accept": "application/vnd.api+json",
45
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
46
    },
47
    body: undefined,
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55