//native
type Formstack = {
token: string;
};
/**
* /form/:id/submission
* Get all submissions for the specified form
*/
export async function main(
auth: Formstack,
id: string,
encryption_password: string | undefined,
min_time: string | undefined,
max_time: string | undefined,
search_field_x: string | undefined,
search_value_x: string | undefined,
page: string | undefined,
per_page: string | undefined,
sort: string | undefined,
data: string | undefined,
expand_data: string | undefined,
X_FS_ENCRYPTION_PASSWORD?: string,
) {
const url = new URL(
`https://www.formstack.com/api/v2/form/${id}/submission.json`,
);
for (const [k, v] of [
["encryption_password", encryption_password],
["min_time", min_time],
["max_time", max_time],
["search_field_x", search_field_x],
["search_value_x", search_value_x],
["page", page],
["per_page", per_page],
["sort", sort],
["data", data],
["expand_data", expand_data],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
...(X_FS_ENCRYPTION_PASSWORD
? { "X-FS-ENCRYPTION-PASSWORD": X_FS_ENCRYPTION_PASSWORD }
: {}),
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago