//native
type Formstack = {
token: string;
};
/**
* /form/:id/field
* Create a new field for the specified form
*/
export async function main(
auth: Formstack,
id: string,
body: {
field_type: string;
label: string;
hide_label?: false | true;
description?: string;
description_callout?: false | true;
default_value?: string;
options?: string[];
options_values?: string[];
required?: false | true;
readonly?: false | true;
hidden?: false | true;
uniq?: false | true;
colspan?: number;
sort?: number;
attributes?: {};
logic?: {};
calculation?: string;
},
) {
const url = new URL(`https://www.formstack.com/api/v2/form/${id}/field.json`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago