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