1 | |
2 | type Klaviyo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Get List |
7 | * Get a list with the given list ID.*Rate limits*:Burst: `75/s`Steady: `700/m`Rate limits when using the `additional-fields[list]=profile_count` parameter in your API request:Burst: `1/s`Steady: `15/m`To learn more about how the `additional-fields` parameter impacts rate limits, check out our [Rate limits, status codes, and errors](https://developers.klaviyo.com/en/v2024-10-15/docs/rate_limits_and_error_handling) guide. |
8 |
|
9 | */ |
10 | export async function main( |
11 | auth: Klaviyo, |
12 | id: string, |
13 | additional_fields_list_: string | undefined, |
14 | fields_flow_: string | undefined, |
15 | fields_list_: string | undefined, |
16 | fields_tag_: string | undefined, |
17 | include: string | undefined, |
18 | revision: string, |
19 | ) { |
20 | const url = new URL(`https://a.klaviyo.com/api/lists/${id}`); |
21 | for (const [k, v] of [ |
22 | ["additional-fields[list]", additional_fields_list_], |
23 | ["fields[flow]", fields_flow_], |
24 | ["fields[list]", fields_list_], |
25 | ["fields[tag]", fields_tag_], |
26 | ["include", include], |
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 |
|