0
List Domains
One script reply has been approved by the moderators Verified

List domains in Mailgun. See the docs here

Created by saskiatychler 929 days ago Viewed 3375 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 229 days ago
1
type Mailgun = {
2
  api_key: string;
3
};
4

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