1 | |
2 | type Klaviyo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Get Bulk Create Coupon Codes Job |
7 | * Get a coupon code bulk create job with the given job ID.*Rate limits*:Burst: `75/s`Steady: `700/m` |
8 |
|
9 | */ |
10 | export async function main( |
11 | auth: Klaviyo, |
12 | job_id: string, |
13 | fields_coupon_code_bulk_create_job_: string | undefined, |
14 | fields_coupon_code_: string | undefined, |
15 | include: string | undefined, |
16 | revision: string, |
17 | ) { |
18 | const url = new URL( |
19 | `https://a.klaviyo.com/api/coupon-code-bulk-create-jobs/${job_id}`, |
20 | ); |
21 | for (const [k, v] of [ |
22 | [ |
23 | "fields[coupon-code-bulk-create-job]", |
24 | fields_coupon_code_bulk_create_job_, |
25 | ], |
26 | ["fields[coupon-code]", fields_coupon_code_], |
27 | ["include", include], |
28 | ]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "GET", |
35 | headers: { |
36 | revision: revision, |
37 | "Accept": "application/vnd.api+json", |
38 | Authorization: "Klaviyo-API-Key " + auth.apiKey, |
39 | }, |
40 | body: undefined, |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|