Delete a zone ruleset
One script reply has been approved by the moderators Verified

Deletes all versions of an existing zone ruleset.

Created by hugo697 848 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 310 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Delete a zone ruleset
8
 * Deletes all versions of an existing zone ruleset.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  ruleset_id: string,
13
  zone_id: string
14
) {
15
  const url = new URL(
16
    `https://api.cloudflare.com/client/v4/zones/${zone_id}/rulesets/${ruleset_id}`
17
  );
18

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