Patch Zero Trust account configuration

Patches the current Zero Trust account configuration. This endpoint can update a single subcollection of settings such as `antivirus`, `tls_decrypt`, `activity_log`, `block_page`, `browser_isolation`, `fips`, `body_scanning`, or `custom_certificate`, without updating the entire configuration object. Returns an error if any collection of settings is not properly configured.

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
 * Patch Zero Trust account configuration
8
 * Patches the current Zero Trust account configuration. This endpoint can update a single subcollection of settings such as `antivirus`, `tls_decrypt`, `activity_log`, `block_page`, `browser_isolation`, `fips`, `body_scanning`, or `custom_certificate`, without updating the entire configuration object. Returns an error if any collection of settings is not properly configured.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  identifier: string,
13
  body: {
14
    settings?: {
15
      activity_log?: { enabled?: boolean; [k: string]: unknown };
16
      antivirus?: {
17
        enabled_download_phase?: boolean;
18
        enabled_upload_phase?: boolean;
19
        fail_closed?: boolean;
20
        [k: string]: unknown;
21
      };
22
      block_page?: {
23
        background_color?: string;
24
        enabled?: boolean;
25
        footer_text?: string;
26
        header_text?: string;
27
        logo_path?: string;
28
        mailto_address?: string;
29
        mailto_subject?: string;
30
        name?: string;
31
        suppress_footer?: boolean;
32
        [k: string]: unknown;
33
      };
34
      body_scanning?: { inspection_mode?: string; [k: string]: unknown };
35
      browser_isolation?: {
36
        non_identity_enabled?: boolean;
37
        url_browser_isolation_enabled?: boolean;
38
        [k: string]: unknown;
39
      };
40
      custom_certificate?: {
41
        binding_status?: string;
42
        enabled: boolean;
43
        id?: string;
44
        updated_at?: string;
45
        [k: string]: unknown;
46
      };
47
      fips?: { tls?: boolean; [k: string]: unknown };
48
      protocol_detection?: { enabled?: boolean; [k: string]: unknown };
49
      tls_decrypt?: { enabled?: boolean; [k: string]: unknown };
50
      [k: string]: unknown;
51
    };
52
    [k: string]: unknown;
53
  }
54
) {
55
  const url = new URL(
56
    `https://api.cloudflare.com/client/v4/accounts/${identifier}/gateway/configuration`
57
  );
58

59
  const response = await fetch(url, {
60
    method: "PATCH",
61
    headers: {
62
      "X-AUTH-EMAIL": auth.email,
63
      "X-AUTH-KEY": auth.key,
64
      "Content-Type": "application/json",
65
      Authorization: "Bearer " + auth.token,
66
    },
67
    body: JSON.stringify(body),
68
  });
69
  if (!response.ok) {
70
    const text = await response.text();
71
    throw new Error(`${response.status} ${text}`);
72
  }
73
  return await response.json();
74
}
75