0

Add User to Workspace

by
Published today

Add an existing instance user to the workspace by email, as a developer, operator or admin. Leave username empty when the instance automates username creation (it rejects one). Requires a workspace admin.

Script windmill Verified

The script

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

3
import * as wmill from "windmill-client"
4

5
// windmill-client errors only carry the status text: throw the response body, which says why
6
wmill.OpenAPI.interceptors.response.use(async (response) => {
7
  if (!response.ok) {
8
    throw new Error(`${response.status} ${await response.text()}`)
9
  }
10
  return response
11
})
12

13
/**
14
 * Add User to Workspace
15
 * Add an existing instance user to the workspace by email, as a developer, operator or admin. Leave username empty when the instance automates username creation (it rejects one). Requires a workspace admin.
16
 */
17
export async function main(
18
  email: string,
19
  role: "developer" | "operator" | "admin" = "developer",
20
  username: string | undefined
21
) {
22
  return await wmill.WorkspaceService.addUser({
23
    workspace: wmill.getWorkspace(),
24
    requestBody: {
25
      email,
26
      is_admin: role === "admin",
27
      operator: role === "operator",
28
      username: username || undefined,
29
    },
30
  })
31
}
32