0

Create Group

by
Published 4 days ago

Create an Okta group with a name and optional description.

Script okta Verified

The script

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

3
/**
4
 * Create Group
5
 * Create an Okta group (OKTA_GROUP type). Provide a unique `name` and an optional `description`.
6
 */
7
export async function main(
8
  auth: RT.Okta,
9
  name: string,
10
  description: string | undefined
11
) {
12
  const url = new URL(`${auth.org_url}/api/v1/groups`)
13

14
  const profile: { [key: string]: any } = { name }
15
  if (description !== undefined && description !== "")
16
    profile.description = description
17

18
  const response = await fetch(url, {
19
    method: "POST",
20
    headers: {
21
      Authorization: `SSWS ${auth.token}`,
22
      "Content-Type": "application/json",
23
      Accept: "application/json",
24
    },
25
    body: JSON.stringify({ profile }),
26
  })
27

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

32
  return await response.json()
33
}
34