1 | |
2 |
|
3 | export type DynSelect_form_id = string |
4 |
|
5 | |
6 | export async function form_id(auth: RT.Hubspot) { |
7 | const response = await fetch( |
8 | "https://api.hubapi.com/marketing/v3/forms?limit=100", |
9 | { |
10 | headers: { |
11 | Authorization: `Bearer ${auth.token}`, |
12 | Accept: "application/json", |
13 | }, |
14 | } |
15 | ) |
16 | if (!response.ok) { |
17 | throw new Error(`${response.status} ${await response.text()}`) |
18 | } |
19 | const { results } = (await response.json()) as { |
20 | results: { id: string; name: string }[] |
21 | } |
22 | return results.map((f) => ({ value: f.id, label: f.name })) |
23 | } |
24 |
|
25 | |
26 | * List Form Submissions |
27 | * List the submissions of a form, most recent first (max 50 per page). Requires the forms scope. |
28 | */ |
29 | export async function main( |
30 | auth: RT.Hubspot, |
31 | form_id: DynSelect_form_id, |
32 | limit: number | undefined, |
33 | after: string | undefined |
34 | ) { |
35 | const url = new URL( |
36 | `https://api.hubapi.com/form-integrations/v1/submissions/forms/${form_id}` |
37 | ) |
38 | if (limit != null) url.searchParams.append("limit", String(limit)) |
39 | if (after != null && after !== "") url.searchParams.append("after", after) |
40 |
|
41 | const response = await fetch(url, { |
42 | headers: { |
43 | Authorization: `Bearer ${auth.token}`, |
44 | Accept: "application/json", |
45 | }, |
46 | }) |
47 |
|
48 | if (!response.ok) { |
49 | throw new Error(`${response.status} ${await response.text()}`) |
50 | } |
51 |
|
52 | return await response.json() |
53 | } |
54 |
|