0
Create Route
One script reply has been approved by the moderators Verified

Create a new route. See the docs here

Created by paulys8ty1 938 days ago Viewed 4149 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
    priority: number;
9
    description: string;
10
    expression: string;
11
    action: string[];
12
  }
13
) {
14
  const form = new FormData();
15
  form.append("priority", data.priority);
16
  form.append("description", data.description);
17
  form.append("expression", data.expression);
18
  form.append("action", data.action);
19

20
  return (
21
    await fetch(`https://api.mailgun.net/v3/routes`, {
22
      method: "POST",
23
      headers: {
24
        Authorization:
25
          "Basic " + Buffer.from(`api:${resource.api_key}`).toString("base64"),
26
      },
27
      body: form,
28
    })
29
  ).json();
30
}
31