0
Get Region
One script reply has been approved by the moderators Verified

Get a single region mapping.

Created by hugo697 175 days ago Viewed 5906 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 175 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get Region
8
 * Get a single region mapping.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  region_code:
13
    | "WNAM"
14
    | "ENAM"
15
    | "WEU"
16
    | "EEU"
17
    | "NSAM"
18
    | "SSAM"
19
    | "OC"
20
    | "ME"
21
    | "NAF"
22
    | "SAF"
23
    | "SAS"
24
    | "SEAS"
25
    | "NEAS",
26
  account_identifier: string
27
) {
28
  const url = new URL(
29
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/load_balancers/regions/${region_code}`
30
  );
31

32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      "X-AUTH-EMAIL": auth.email,
36
      "X-AUTH-KEY": auth.key,
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47