1 | |
2 | type Klaviyo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Get Actions for Flow |
7 | * Get all flow actions associated with the given flow ID. |
8 |
|
9 | Returns a maximum of 50 flows per request, which can be paginated with cursor-based pagination.*Rate limits*:Burst: `3/s`Steady: `60/m` |
10 |
|
11 | */ |
12 | export async function main( |
13 | auth: Klaviyo, |
14 | id: string, |
15 | fields_flow_action_: string | undefined, |
16 | filter: string | undefined, |
17 | page_cursor_: string | undefined, |
18 | page_size_: string | undefined, |
19 | sort: |
20 | | "action_type" |
21 | | "-action_type" |
22 | | "created" |
23 | | "-created" |
24 | | "id" |
25 | | "-id" |
26 | | "status" |
27 | | "-status" |
28 | | "updated" |
29 | | "-updated" |
30 | | undefined, |
31 | revision: string, |
32 | ) { |
33 | const url = new URL(`https://a.klaviyo.com/api/flows/${id}/flow-actions`); |
34 | for (const [k, v] of [ |
35 | ["fields[flow-action]", fields_flow_action_], |
36 | ["filter", filter], |
37 | ["page[cursor]", page_cursor_], |
38 | ["page[size]", page_size_], |
39 | ["sort", sort], |
40 | ]) { |
41 | if (v !== undefined && v !== "" && k !== undefined) { |
42 | url.searchParams.append(k, v); |
43 | } |
44 | } |
45 | const response = await fetch(url, { |
46 | method: "GET", |
47 | headers: { |
48 | revision: revision, |
49 | "Accept": "application/vnd.api+json", |
50 | Authorization: "Klaviyo-API-Key " + auth.apiKey, |
51 | }, |
52 | body: undefined, |
53 | }); |
54 | if (!response.ok) { |
55 | const text = await response.text(); |
56 | throw new Error(`${response.status} ${text}`); |
57 | } |
58 | return await response.json(); |
59 | } |
60 |
|