1
//native
2
type Buttondown = {
3
token: string;
4
};
5
/**
6
* Update Survey
7
*
8
*/
9
export async function main(
10
auth: Buttondown,
11
id: string,
12
body: {
13
notes?: string;
14
answers?: string[];
15
response_cadence?: "once" | "once_per_email";
16
status?: "active" | "inactive";
17
is_freeform_response_enabled?: false | true;
18
},
19
) {
20
const url = new URL(`https://api.buttondown.com/v1/surveys/${id}`);
21
22
const response = await fetch(url, {
23
method: "PATCH",
24
headers: {
25
"Content-Type": "application/json",
26
Authorization: "Token " + auth.token,
27
28
body: JSON.stringify(body),
29
});
30
if (!response.ok) {
31
const text = await response.text();
32
throw new Error(`${response.status} ${text}`);
33
}
34
return await response.json();
35
36