1 | |
2 | type Klaviyo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Bulk Create Catalog Variants |
7 | * Create a catalog variant bulk create job to create 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-create-job"; |
19 | attributes: { |
20 | variants: { |
21 | data: { |
22 | type: "catalog-variant"; |
23 | attributes: { |
24 | external_id: string; |
25 | catalog_type?: string; |
26 | integration_type?: "$custom"; |
27 | title: string; |
28 | description: string; |
29 | sku: string; |
30 | inventory_policy?: 0 | 1 | 2; |
31 | inventory_quantity: number; |
32 | price: number; |
33 | url: string; |
34 | image_full_url?: string; |
35 | image_thumbnail_url?: string; |
36 | images?: string[]; |
37 | custom_metadata?: {}; |
38 | published?: false | true; |
39 | }; |
40 | relationships?: { |
41 | item?: { data?: { type: "catalog-item"; id: string } }; |
42 | }; |
43 | }[]; |
44 | }; |
45 | }; |
46 | }; |
47 | }, |
48 | ) { |
49 | const url = new URL( |
50 | `https://a.klaviyo.com/api/catalog-variant-bulk-create-jobs`, |
51 | ); |
52 |
|
53 | const response = await fetch(url, { |
54 | method: "POST", |
55 | headers: { |
56 | revision: revision, |
57 | "Accept": "application/vnd.api+json", |
58 | "Content-Type": "application/vnd.api+json", |
59 | Authorization: "Klaviyo-API-Key " + auth.apiKey, |
60 | }, |
61 | body: JSON.stringify(body), |
62 | }); |
63 | if (!response.ok) { |
64 | const text = await response.text(); |
65 | throw new Error(`${response.status} ${text}`); |
66 | } |
67 | return await response.json(); |
68 | } |
69 |
|