0

Create Catalog Item

by
Published Apr 8, 2025

Create a new catalog item.*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
 * Create Catalog Item
7
 * Create a new catalog item.*Rate limits*:Burst: `75/s`Steady: `700/m`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  revision: string,
13
  body: {
14
    data: {
15
      type: "catalog-item";
16
      attributes: {
17
        external_id: string;
18
        integration_type?: "$custom";
19
        title: string;
20
        price?: number;
21
        catalog_type?: string;
22
        description: string;
23
        url: string;
24
        image_full_url?: string;
25
        image_thumbnail_url?: string;
26
        images?: string[];
27
        custom_metadata?: {};
28
        published?: false | true;
29
      };
30
      relationships?: {
31
        categories?: { data?: { type: "catalog-category"; id: string }[] };
32
      };
33
    };
34
  },
35
) {
36
  const url = new URL(`https://a.klaviyo.com/api/catalog-items`);
37

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