//native
type Buttondown = {
token: string;
};
/**
* Retrieve Survey Responses
*
*/
export async function main(
auth: Buttondown,
email: string | undefined,
subscriber: string | undefined,
survey: string | undefined,
creation_date__start: string | undefined,
creation_date__end: string | undefined,
expand: string | undefined,
) {
const url = new URL(`https://api.buttondown.com/v1/survey_responses`);
for (const [k, v] of [
["email", email],
["subscriber", subscriber],
["survey", survey],
["creation_date__start", creation_date__start],
["creation_date__end", creation_date__end],
["expand", expand],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Token " + 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 428 days ago