0

Create Group

by
Published 20 days ago

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 9 days 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({
23
        email,
24
        name: name || undefined,
25
        description: description || undefined,
26
      }),
27
    },
28
  )
29

30
  if (!response.ok) {
31
    throw new Error(`${response.status} ${await response.text()}`)
32
  }
33

34
  return await response.json()
35
}
36