0

Update Catalog Variant

by
Published Apr 8, 2025

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