1 | |
2 | type Klaviyo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Get Bulk Import Profiles Jobs |
7 | * Get all bulk profile import jobs. |
8 |
|
9 | Returns a maximum of 100 jobs per request.*Rate limits*:Burst: `10/s`Steady: `150/m` |
10 |
|
11 | */ |
12 | export async function main( |
13 | auth: Klaviyo, |
14 | fields_profile_bulk_import_job_: string | undefined, |
15 | filter: string | undefined, |
16 | page_cursor_: string | undefined, |
17 | page_size_: string | undefined, |
18 | sort: "created_at" | "-created_at" | undefined, |
19 | revision: string, |
20 | ) { |
21 | const url = new URL(`https://a.klaviyo.com/api/profile-bulk-import-jobs`); |
22 | for (const [k, v] of [ |
23 | ["fields[profile-bulk-import-job]", fields_profile_bulk_import_job_], |
24 | ["filter", filter], |
25 | ["page[cursor]", page_cursor_], |
26 | ["page[size]", page_size_], |
27 | ["sort", sort], |
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 |
|