Update a WAF rule group

Updates a WAF rule group. You can update the state (`mode` parameter) of a rule group. **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
 * Update a WAF rule group
8
 * Updates a WAF rule group. You can update the state (`mode` parameter) of a rule group.
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
  identifier: string,
15
  package_identifier: string,
16
  zone_identifier: string,
17
  body: { mode?: "on" | "off"; [k: string]: unknown }
18
) {
19
  const url = new URL(
20
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/firewall/waf/packages/${package_identifier}/groups/${identifier}`
21
  );
22

23
  const response = await fetch(url, {
24
    method: "PATCH",
25
    headers: {
26
      "X-AUTH-EMAIL": auth.email,
27
      "X-AUTH-KEY": auth.key,
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39