0

Create Group

by
Published today

Create a group with the given email address (on one of the account's domains), display name and description.

Script gworkspace Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 1 hour ago
1
//native
2

3
/**
4
 * Create Group
5
 * Create a group with the given email address (on one of the account's domains), display name and description.
6
 */
7
export async function main(
8
  auth: RT.Gworkspace,
9
  email: string,
10
  name: string | undefined,
11
  description: string | undefined,
12
) {
13
  const response = await fetch(
14
    "https://admin.googleapis.com/admin/directory/v1/groups",
15
    {
16
      method: "POST",
17
      headers: {
18
        Authorization: `Bearer ${auth.token}`,
19
        "Content-Type": "application/json",
20
        Accept: "application/json",
21
      },
22
      body: JSON.stringify({ email, name, description }),
23
    },
24
  )
25

26
  if (!response.ok) {
27
    throw new Error(`${response.status} ${await response.text()}`)
28
  }
29

30
  return await response.json()
31
}
32