0

Get Catalog Items

by
Published Apr 8, 2025

Get all catalog items in an account. Catalog items can be sorted by the following fields, in ascending and descending order: `created` Currently, the only supported integration type is `$custom`, and the only supported catalog type is `$default`. Returns a maximum of 100 items per request.*Rate limits*:Burst: `350/s`Steady: `3500/m` **Scopes:** `catalogs: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 Catalog Items
7
 * Get all catalog items in an account.
8

9
Catalog items can be sorted by the following fields, in ascending and descending order:
10
`created`
11

12
Currently, the only supported integration type is `$custom`, and the only supported catalog type is `$default`.
13

14
Returns a maximum of 100 items per request.*Rate limits*:Burst: `350/s`Steady: `3500/m`
15

16
 */
17
export async function main(
18
  auth: Klaviyo,
19
  fields_catalog_item_: string | undefined,
20
  fields_catalog_variant_: string | undefined,
21
  filter: string | undefined,
22
  include: string | undefined,
23
  page_cursor_: string | undefined,
24
  sort: "created" | "-created" | undefined,
25
  revision: string,
26
) {
27
  const url = new URL(`https://a.klaviyo.com/api/catalog-items`);
28
  for (const [k, v] of [
29
    ["fields[catalog-item]", fields_catalog_item_],
30
    ["fields[catalog-variant]", fields_catalog_variant_],
31
    ["filter", filter],
32
    ["include", include],
33
    ["page[cursor]", page_cursor_],
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