Update a user seat

Removes a user from a Zero Trust seat when both `access_seat` and `gateway_seat` are set to false.

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 a user seat
8
 * Removes a user from a Zero Trust seat when both `access_seat` and `gateway_seat` are set to false.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  identifier: string,
13
  body: {
14
    access_seat: boolean;
15
    gateway_seat: boolean;
16
    seat_uid: { [k: string]: unknown };
17
    [k: string]: unknown;
18
  }[]
19
) {
20
  const url = new URL(
21
    `https://api.cloudflare.com/client/v4/accounts/${identifier}/access/seats`
22
  );
23

24
  const response = await fetch(url, {
25
    method: "PATCH",
26
    headers: {
27
      "X-AUTH-EMAIL": auth.email,
28
      "X-AUTH-KEY": auth.key,
29
      "Content-Type": "application/json",
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40