Update your Zero Trust organization

Updates the configuration for your Zero Trust organization.

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 your Zero Trust organization
8
 * Updates the configuration for your Zero Trust organization.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  identifier: string,
13
  body: {
14
    auth_domain?: string;
15
    is_ui_read_only?: boolean;
16
    login_design?: {
17
      background_color?: string;
18
      footer_text?: string;
19
      header_text?: string;
20
      logo_path?: string;
21
      text_color?: string;
22
      [k: string]: unknown;
23
    };
24
    name?: string;
25
    ui_read_only_toggle_reason?: string;
26
    user_seat_expiration_inactive_time?: string;
27
    [k: string]: unknown;
28
  }
29
) {
30
  const url = new URL(
31
    `https://api.cloudflare.com/client/v4/zones/${identifier}/access/organizations`
32
  );
33

34
  const response = await fetch(url, {
35
    method: "PUT",
36
    headers: {
37
      "X-AUTH-EMAIL": auth.email,
38
      "X-AUTH-KEY": auth.key,
39
      "Content-Type": "application/json",
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: JSON.stringify(body),
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50