0
Get an Access policy
One script reply has been approved by the moderators Verified

Fetches a single Access policy.

Created by hugo697 297 days ago Viewed 8984 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 297 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get an Access policy
8
 * Fetches a single Access policy.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  uuid: string,
13
  uuid1: string,
14
  identifier: string
15
) {
16
  const url = new URL(
17
    `https://api.cloudflare.com/client/v4/zones/${identifier}/access/apps/${uuid1}/policies/${uuid}`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "GET",
22
    headers: {
23
      "X-AUTH-EMAIL": auth.email,
24
      "X-AUTH-KEY": auth.key,
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35