1 | |
2 | type Klaviyo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Get Update Variants Job |
7 | * Get a catalog variate bulk update job with the given job ID. |
8 |
|
9 | An `include` parameter can be provided to get the following related resource data: `variants`.*Rate limits*:Burst: `350/s`Steady: `3500/m` |
10 |
|
11 | */ |
12 | export async function main( |
13 | auth: Klaviyo, |
14 | job_id: string, |
15 | fields_catalog_variant_bulk_update_job_: string | undefined, |
16 | fields_catalog_variant_: string | undefined, |
17 | include: string | undefined, |
18 | revision: string, |
19 | ) { |
20 | const url = new URL( |
21 | `https://a.klaviyo.com/api/catalog-variant-bulk-update-jobs/${job_id}`, |
22 | ); |
23 | for (const [k, v] of [ |
24 | [ |
25 | "fields[catalog-variant-bulk-update-job]", |
26 | fields_catalog_variant_bulk_update_job_, |
27 | ], |
28 | ["fields[catalog-variant]", fields_catalog_variant_], |
29 | ["include", include], |
30 | ]) { |
31 | if (v !== undefined && v !== "" && k !== undefined) { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "GET", |
37 | headers: { |
38 | revision: revision, |
39 | "Accept": "application/vnd.api+json", |
40 | Authorization: "Klaviyo-API-Key " + auth.apiKey, |
41 | }, |
42 | body: undefined, |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.json(); |
49 | } |
50 |
|