0

Bulk Update Catalog Variants

by
Published Apr 8, 2025

Create a catalog variant bulk update job to update a batch of catalog variants. Accepts up to 100 catalog variants 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 Update Catalog Variants
7
 * Create a catalog variant bulk update job to update a batch of catalog variants.
8

9
Accepts up to 100 catalog variants 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-variant-bulk-update-job";
19
      attributes: {
20
        variants: {
21
          data: {
22
            type: "catalog-variant";
23
            id: string;
24
            attributes: {
25
              title?: string;
26
              description?: string;
27
              sku?: string;
28
              inventory_policy?: 0 | 1 | 2;
29
              inventory_quantity?: number;
30
              price?: number;
31
              url?: string;
32
              image_full_url?: string;
33
              image_thumbnail_url?: string;
34
              images?: string[];
35
              custom_metadata?: {};
36
              published?: false | true;
37
            };
38
          }[];
39
        };
40
      };
41
    };
42
  },
43
) {
44
  const url = new URL(
45
    `https://a.klaviyo.com/api/catalog-variant-bulk-update-jobs`,
46
  );
47

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