Get a zone entry point ruleset version

Fetches a specific version of a zone entry point ruleset.

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
 * Get a zone entry point ruleset version
8
 * Fetches a specific version of a zone entry point ruleset.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  ruleset_version: string,
13
  ruleset_phase:
14
    | "ddos_l4"
15
    | "ddos_l7"
16
    | "http_config_settings"
17
    | "http_custom_errors"
18
    | "http_log_custom_fields"
19
    | "http_ratelimit"
20
    | "http_request_cache_settings"
21
    | "http_request_dynamic_redirect"
22
    | "http_request_firewall_custom"
23
    | "http_request_firewall_managed"
24
    | "http_request_late_transform"
25
    | "http_request_origin"
26
    | "http_request_redirect"
27
    | "http_request_sanitize"
28
    | "http_request_sbfm"
29
    | "http_request_select_configuration"
30
    | "http_request_transform"
31
    | "http_response_compression"
32
    | "http_response_firewall_managed"
33
    | "http_response_headers_transform"
34
    | "magic_transit"
35
    | "magic_transit_ids_managed"
36
    | "magic_transit_managed",
37
  zone_id: string
38
) {
39
  const url = new URL(
40
    `https://api.cloudflare.com/client/v4/zones/${zone_id}/rulesets/phases/${ruleset_phase}/entrypoint/versions/${ruleset_version}`
41
  );
42

43
  const response = await fetch(url, {
44
    method: "GET",
45
    headers: {
46
      "X-AUTH-EMAIL": auth.email,
47
      "X-AUTH-KEY": auth.key,
48
      Authorization: "Bearer " + auth.token,
49
    },
50
    body: undefined,
51
  });
52
  if (!response.ok) {
53
    const text = await response.text();
54
    throw new Error(`${response.status} ${text}`);
55
  }
56
  return await response.json();
57
}
58