0

Bulk Delete Catalog Categories

by
Published Apr 8, 2025

Create a catalog category bulk delete job to delete a batch of catalog categories. Accepts up to 100 catalog categories per request. The maximum allowed payload size is 5MB. The maximum number of jobs in progress at one time is 500.*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
 * Bulk Delete Catalog Categories
7
 * Create a catalog category bulk delete job to delete a batch of catalog categories.
8

9
Accepts up to 100 catalog categories per request. The maximum allowed payload size is 5MB.
10
The maximum number of jobs in progress at one time is 500.*Rate limits*:Burst: `75/s`Steady: `700/m`
11

12
 */
13
export async function main(
14
  auth: Klaviyo,
15
  revision: string,
16
  body: {
17
    data: {
18
      type: "catalog-category-bulk-delete-job";
19
      attributes: {
20
        categories: { data: { type: "catalog-category"; id: string }[] };
21
      };
22
    };
23
  },
24
) {
25
  const url = new URL(
26
    `https://a.klaviyo.com/api/catalog-category-bulk-delete-jobs`,
27
  );
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      revision: revision,
33
      "Accept": "application/vnd.api+json",
34
      "Content-Type": "application/vnd.api+json",
35
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45