create user (require admin privilege)

Script windmill Verified

by admin ยท 8/13/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * create user (require admin privilege)
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  body: {
8
    email: string;
9
    username: string;
10
    is_admin: boolean;
11
    [k: string]: unknown;
12
  }
13
) {
14
  const url = new URL(`${BASE_URL}/api/w/${workspace}/users/add`);
15

16
  const response = await fetch(url, {
17
    method: "POST",
18
    headers: {
19
      "Content-Type": "application/json",
20
      Authorization: "Bearer " + WM_TOKEN,
21
    },
22
    body: JSON.stringify(body),
23
  });
24
  if (!response.ok) {
25
    const text = await response.text();
26
    throw new Error(`${response.status} ${text}`);
27
  }
28
  return await response.text();
29
}
30