0

Create a user

by
Published Oct 17, 2025

Can be used by the following roles assigned at the organization scope: - ORG_ADMIN

Script cockroachdb Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Cockroachdb = {
3
  token: string;
4
};
5
/**
6
 * Create a user
7
 * Can be used by the following roles assigned at the organization scope:
8
- ORG_ADMIN
9

10
 */
11
export async function main(
12
  auth: Cockroachdb,
13
  body: {
14
    active?: false | true;
15
    displayName?: string;
16
    emails: {
17
      display?: string;
18
      primary?: false | true;
19
      type?: string;
20
      value: string;
21
    }[];
22
    externalId?: string;
23
    name?: { familyName?: string; givenName?: string };
24
    schemas: string[];
25
    userName?: string;
26
  },
27
) {
28
  const url = new URL(`https://cockroachlabs.cloud/api/scim/v2/Users`);
29

30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44