0
Get Mailing List Members
One script reply has been approved by the moderators Verified

List all mailing list members. See the docs here

Created by paulesterina 938 days ago Viewed 4166 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 238 days ago
1
type Mailgun = {
2
  api_key: string;
3
};
4

5
export async function main(
6
  resource: Mailgun,
7
  data: {
8
    listAddress: string;
9
    query: {
10
      address?: string;
11
      subscribed?: boolean;
12
      limit?: number;
13
      skip?: number;
14
    };
15
  }
16
) {
17
  return (
18
    await fetch(
19
      `https://api.mailgun.net/v3/lists/${data.listAddress}/members?${
20
        data.query.address && `address=${data.query.address}`
21
      }${
22
        data.query.subscribed && `&subscribed=${data.query.subscribed}`
23
      }&limit=${data.query.limit ?? 100}&skip=${data.query.skip ?? 0}`,
24
      {
25
        method: "GET",
26
        headers: {
27
          Authorization:
28
            "Basic " +
29
            Buffer.from(`api:${resource.api_key}`).toString("base64"),
30
        },
31
      }
32
    )
33
  ).json();
34
}
35