0

Remove Items from Catalog Category

by
Published Apr 8, 2025

Delete item relationships for the given category ID.*Rate limits*:Burst: `75/s`Steady: `700/m` **Scopes:** `catalogs:write`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Remove Items from Catalog Category
7
 * Delete item relationships for the given category ID.*Rate limits*:Burst: `75/s`Steady: `700/m`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  id: string,
13
  revision: string,
14
  body: { data: { type: "catalog-item"; id: string }[] },
15
) {
16
  const url = new URL(
17
    `https://a.klaviyo.com/api/catalog-categories/${id}/relationships/items`,
18
  );
19

20
  const response = await fetch(url, {
21
    method: "DELETE",
22
    headers: {
23
      revision: revision,
24
      "Accept": "application/vnd.api+json",
25
      "Content-Type": "application/vnd.api+json",
26
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36