List WAF overrides

Fetches the URI-based WAF overrides in a zone. **Note:** Applies only to the [previous version of WAF managed rules](https://developers.cloudflare.com/support/firewall/managed-rules-web-application-firewall-waf/understanding-waf-managed-rules-web-application-firewall/).

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * List WAF overrides
8
 * Fetches the URI-based WAF overrides in a zone.
9

10
**Note:** Applies only to the [previous version of WAF managed rules](https://developers.cloudflare.com/support/firewall/managed-rules-web-application-firewall-waf/understanding-waf-managed-rules-web-application-firewall/).
11
 */
12
export async function main(
13
  auth: Cloudflare,
14
  zone_identifier: string,
15
  page: string | undefined,
16
  per_page: string | undefined
17
) {
18
  const url = new URL(
19
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/firewall/waf/overrides`
20
  );
21
  for (const [k, v] of [
22
    ["page", page],
23
    ["per_page", per_page],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      "X-AUTH-EMAIL": auth.email,
33
      "X-AUTH-KEY": auth.key,
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44