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