1 | |
2 | type Formstack = { |
3 | token: string; |
4 | }; |
5 | |
6 | * /form/:id/partialsubmission |
7 | * Get all partial submissions for the specified form |
8 | */ |
9 | export async function main( |
10 | auth: Formstack, |
11 | id: string, |
12 | encryption_password: string | undefined, |
13 | min_time: string | undefined, |
14 | max_time: string | undefined, |
15 | search_field_x: string | undefined, |
16 | search_value_x: string | undefined, |
17 | page: string | undefined, |
18 | per_page: string | undefined, |
19 | sort: string | undefined, |
20 | data: string | undefined, |
21 | expand_data: string | undefined, |
22 | ) { |
23 | const url = new URL( |
24 | `https://www.formstack.com/api/v2/form/${id}/partialsubmission.json`, |
25 | ); |
26 | for (const [k, v] of [ |
27 | ["encryption_password", encryption_password], |
28 | ["min_time", min_time], |
29 | ["max_time", max_time], |
30 | ["search_field_x", search_field_x], |
31 | ["search_value_x", search_value_x], |
32 | ["page", page], |
33 | ["per_page", per_page], |
34 | ["sort", sort], |
35 | ["data", data], |
36 | ["expand_data", expand_data], |
37 | ]) { |
38 | if (v !== undefined && v !== "" && k !== undefined) { |
39 | url.searchParams.append(k, v); |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: "GET", |
44 | headers: { |
45 | Authorization: "Bearer " + auth.token, |
46 | }, |
47 | body: undefined, |
48 | }); |
49 | if (!response.ok) { |
50 | const text = await response.text(); |
51 | throw new Error(`${response.status} ${text}`); |
52 | } |
53 | return await response.json(); |
54 | } |
55 |
|