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