0

Get Item IDs for Catalog Category

by
Published Apr 8, 2025

Get all items in the given category ID. 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 Item IDs for Catalog Category
7
 * Get all items in the given category ID.
8

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

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