0

Update group

by
Published Oct 17, 2025

Updates a specific group. Only admins of this group or users with admin-level permissions will be able to use this API.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Update group
7
 * Updates a specific group. Only admins of this
8
group or users with admin-level permissions will be able to
9
use this API.
10
 */
11
export async function main(
12
  auth: Box,
13
  group_id: string,
14
  fields: string | undefined,
15
  body: {
16
    name?: string;
17
    provenance?: string;
18
    external_sync_identifier?: string;
19
    description?: string;
20
    invitability_level?:
21
      | "admins_only"
22
      | "admins_and_members"
23
      | "all_managed_users";
24
    member_viewability_level?:
25
      | "admins_only"
26
      | "admins_and_members"
27
      | "all_managed_users";
28
  },
29
) {
30
  const url = new URL(`https://api.box.com/2.0/groups/${group_id}`);
31
  for (const [k, v] of [["fields", fields]]) {
32
    if (v !== undefined && v !== "" && k !== undefined) {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "PUT",
38
    headers: {
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