0

Update Catalog Category

by
Published Apr 8, 2025

Update a catalog category with 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
 * Update Catalog Category
7
 * Update a catalog category with 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: {
15
    data: {
16
      type: "catalog-category";
17
      id: string;
18
      attributes: { name?: string };
19
      relationships?: {
20
        items?: { data?: { type: "catalog-item"; id: string }[] };
21
      };
22
    };
23
  },
24
) {
25
  const url = new URL(`https://a.klaviyo.com/api/catalog-categories/${id}`);
26

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