0

Create Catalog Variant

by
Published Apr 8, 2025

Create a new variant for a related 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 Variant
7
 * Create a new variant for a related 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-variant";
16
      attributes: {
17
        external_id: string;
18
        catalog_type?: string;
19
        integration_type?: "$custom";
20
        title: string;
21
        description: string;
22
        sku: string;
23
        inventory_policy?: 0 | 1 | 2;
24
        inventory_quantity: number;
25
        price: number;
26
        url: string;
27
        image_full_url?: string;
28
        image_thumbnail_url?: string;
29
        images?: string[];
30
        custom_metadata?: {};
31
        published?: false | true;
32
      };
33
      relationships?: {
34
        item?: { data?: { type: "catalog-item"; id: string } };
35
      };
36
    };
37
  },
38
) {
39
  const url = new URL(`https://a.klaviyo.com/api/catalog-variants`);
40

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