0

Update Catalog Item

by
Published Apr 8, 2025

Update a catalog item with the given item 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 Item
7
 * Update a catalog item with the given item 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-item";
17
      id: string;
18
      attributes: {
19
        title?: string;
20
        price?: number;
21
        description?: string;
22
        url?: string;
23
        image_full_url?: string;
24
        image_thumbnail_url?: string;
25
        images?: string[];
26
        custom_metadata?: {};
27
        published?: false | true;
28
      };
29
      relationships?: {
30
        categories?: { data?: { type: "catalog-category"; id: string }[] };
31
      };
32
    };
33
  },
34
) {
35
  const url = new URL(`https://a.klaviyo.com/api/catalog-items/${id}`);
36

37
  const response = await fetch(url, {
38
    method: "PATCH",
39
    headers: {
40
      revision: revision,
41
      "Accept": "application/vnd.api+json",
42
      "Content-Type": "application/vnd.api+json",
43
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
44
    },
45
    body: JSON.stringify(body),
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53