0

List Subscribers

by
Published Apr 8, 2025
Script buttondown Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Buttondown = {
3
  token: string;
4
};
5
/**
6
 * List Subscribers
7
 *
8
 */
9
export async function main(
10
  auth: Buttondown,
11
  type: string | undefined,
12
  ids: string | undefined,
13
  email_address: string | undefined,
14
  tag: string | undefined,
15
  _tag: string | undefined,
16
  ordering: string | undefined,
17
  utm_source: string | undefined,
18
  price: string | undefined,
19
  coupon: string | undefined,
20
  referral_code: string | undefined,
21
  date: string | undefined,
22
  last_open_date: string | undefined,
23
  last_click_date: string | undefined,
24
  subscriber_import: string | undefined,
25
  expand: string | undefined,
26
  ip_address: string | undefined,
27
  referrer_url: string | undefined,
28
  upgrade_date__start: string | undefined,
29
  upgrade_date__end: string | undefined,
30
) {
31
  const url = new URL(`https://api.buttondown.com/v1/subscribers`);
32
  for (const [k, v] of [
33
    ["type", type],
34
    ["ids", ids],
35
    ["email_address", email_address],
36
    ["tag", tag],
37
    ["-tag", _tag],
38
    ["ordering", ordering],
39
    ["utm_source", utm_source],
40
    ["price", price],
41
    ["coupon", coupon],
42
    ["referral_code", referral_code],
43
    ["date", date],
44
    ["last_open_date", last_open_date],
45
    ["last_click_date", last_click_date],
46
    ["subscriber_import", subscriber_import],
47
    ["expand", expand],
48
    ["ip_address", ip_address],
49
    ["referrer_url", referrer_url],
50
    ["upgrade_date__start", upgrade_date__start],
51
    ["upgrade_date__end", upgrade_date__end],
52
  ]) {
53
    if (v !== undefined && v !== "" && k !== undefined) {
54
      url.searchParams.append(k, v);
55
    }
56
  }
57
  const response = await fetch(url, {
58
    method: "GET",
59
    headers: {
60
      Authorization: "Token " + auth.token,
61
    },
62
    body: undefined,
63
  });
64
  if (!response.ok) {
65
    const text = await response.text();
66
    throw new Error(`${response.status} ${text}`);
67
  }
68
  return await response.json();
69
}
70