0

Create group

by
Published Oct 17, 2025

Creates a new group of users in an enterprise. Only users with admin permissions can create new groups.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Create group
7
 * Creates a new group of users in an enterprise. Only users with admin
8
permissions can create new groups.
9
 */
10
export async function main(
11
  auth: Box,
12
  fields: string | undefined,
13
  body: {
14
    name: string;
15
    provenance?: string;
16
    external_sync_identifier?: string;
17
    description?: string;
18
    invitability_level?:
19
      | "admins_only"
20
      | "admins_and_members"
21
      | "all_managed_users";
22
    member_viewability_level?:
23
      | "admins_only"
24
      | "admins_and_members"
25
      | "all_managed_users";
26
  },
27
) {
28
  const url = new URL(`https://api.box.com/2.0/groups`);
29
  for (const [k, v] of [["fields", fields]]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "POST",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Bearer " + auth.token,
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48