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