0

Bulk Create Catalog Items

by
Published Apr 8, 2025

Create a catalog item bulk create job to create a batch of catalog items. Accepts up to 100 catalog items 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 Create Catalog Items
7
 * Create a catalog item bulk create job to create a batch of catalog items.
8

9
Accepts up to 100 catalog items 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-item-bulk-create-job";
19
      attributes: {
20
        items: {
21
          data: {
22
            type: "catalog-item";
23
            attributes: {
24
              external_id: string;
25
              integration_type?: "$custom";
26
              title: string;
27
              price?: number;
28
              catalog_type?: string;
29
              description: string;
30
              url: string;
31
              image_full_url?: string;
32
              image_thumbnail_url?: string;
33
              images?: string[];
34
              custom_metadata?: {};
35
              published?: false | true;
36
            };
37
            relationships?: {
38
              categories?: {
39
                data?: { type: "catalog-category"; id: string }[];
40
              };
41
            };
42
          }[];
43
        };
44
      };
45
    };
46
  },
47
) {
48
  const url = new URL(
49
    `https://a.klaviyo.com/api/catalog-item-bulk-create-jobs`,
50
  );
51

52
  const response = await fetch(url, {
53
    method: "POST",
54
    headers: {
55
      revision: revision,
56
      "Accept": "application/vnd.api+json",
57
      "Content-Type": "application/vnd.api+json",
58
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
59
    },
60
    body: JSON.stringify(body),
61
  });
62
  if (!response.ok) {
63
    const text = await response.text();
64
    throw new Error(`${response.status} ${text}`);
65
  }
66
  return await response.json();
67
}
68