Update Zone Bot Management Config

Updates the Bot Management configuration for a zone. This API is used to update: - **Bot Fight Mode** - **Super Bot Fight Mode** - **Bot Management for Enterprise** See [Bot Plans](https://developers.cloudflare.com/bots/plans/) for more information on the different plans

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 Zone Bot Management Config
8
 * Updates the Bot Management configuration for a zone.
9

10
This API is used to update:
11
- **Bot Fight Mode**
12
- **Super Bot Fight Mode**
13
- **Bot Management for Enterprise**
14

15
See [Bot Plans](https://developers.cloudflare.com/bots/plans/) for more information on the different plans
16

17
 */
18
export async function main(
19
  auth: Cloudflare,
20
  zone_identifier: string,
21
  Cloudflare_Version: string,
22
  body:
23
    | ({
24
        enable_js?: boolean;
25
        using_latest_model?: boolean;
26
        [k: string]: unknown;
27
      } & { fight_mode?: boolean; [k: string]: unknown })
28
    | ({
29
        enable_js?: boolean;
30
        using_latest_model?: boolean;
31
        [k: string]: unknown;
32
      } & {
33
        optimize_wordpress?: boolean;
34
        sbfm_definitely_automated?: "allow" | "block" | "managed_challenge";
35
        sbfm_static_resource_protection?: boolean;
36
        sbfm_verified_bots?: "allow" | "block";
37
        [k: string]: unknown;
38
      })
39
    | ({
40
        enable_js?: boolean;
41
        using_latest_model?: boolean;
42
        [k: string]: unknown;
43
      } & {
44
        optimize_wordpress?: boolean;
45
        sbfm_definitely_automated?: "allow" | "block" | "managed_challenge";
46
        sbfm_static_resource_protection?: boolean;
47
        sbfm_verified_bots?: "allow" | "block";
48
        [k: string]: unknown;
49
      } & {
50
        sbfm_likely_automated?: "allow" | "block" | "managed_challenge";
51
        [k: string]: unknown;
52
      })
53
    | ({
54
        enable_js?: boolean;
55
        using_latest_model?: boolean;
56
        [k: string]: unknown;
57
      } & {
58
        auto_update_model?: boolean;
59
        suppress_session_score?: boolean;
60
        [k: string]: unknown;
61
      })
62
) {
63
  const url = new URL(
64
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/bot_management`
65
  );
66

67
  const response = await fetch(url, {
68
    method: "PUT",
69
    headers: {
70
      "Cloudflare-Version": Cloudflare_Version,
71
      "X-AUTH-EMAIL": auth.email,
72
      "X-AUTH-KEY": auth.key,
73
      "Content-Type": "application/json",
74
      Authorization: "Bearer " + auth.token,
75
    },
76
    body: JSON.stringify(body),
77
  });
78
  if (!response.ok) {
79
    const text = await response.text();
80
    throw new Error(`${response.status} ${text}`);
81
  }
82
  return await response.json();
83
}
84