//native
type Buttondown = {
token: string;
};
/**
* List Subscribers
*
*/
export async function main(
auth: Buttondown,
type: string | undefined,
ids: string | undefined,
email_address: string | undefined,
tag: string | undefined,
_tag: string | undefined,
ordering: string | undefined,
utm_source: string | undefined,
price: string | undefined,
coupon: string | undefined,
referral_code: string | undefined,
date: string | undefined,
last_open_date: string | undefined,
last_click_date: string | undefined,
subscriber_import: string | undefined,
expand: string | undefined,
ip_address: string | undefined,
referrer_url: string | undefined,
upgrade_date__start: string | undefined,
upgrade_date__end: string | undefined,
) {
const url = new URL(`https://api.buttondown.com/v1/subscribers`);
for (const [k, v] of [
["type", type],
["ids", ids],
["email_address", email_address],
["tag", tag],
["-tag", _tag],
["ordering", ordering],
["utm_source", utm_source],
["price", price],
["coupon", coupon],
["referral_code", referral_code],
["date", date],
["last_open_date", last_open_date],
["last_click_date", last_click_date],
["subscriber_import", subscriber_import],
["expand", expand],
["ip_address", ip_address],
["referrer_url", referrer_url],
["upgrade_date__start", upgrade_date__start],
["upgrade_date__end", upgrade_date__end],
]) {
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