Get list of users from current workspace

Using the openapi https://app.windmill.dev/openapi.html#/ and retrives the list of users in the current workspace.

Script windmill Verified

by sindre svendby964 ยท 9/1/2023

The script

Submitted by sindre svendby964 Deno
Verified 933 days ago
1
// import * as wmill from "npm:windmill-client@1"
2

3
export async function main() {
4
  const workspace = Deno.env.get("WM_WORKSPACE");
5
  const baseUrl = Deno.env.get("WM_BASE_URL");
6
  const url = `${baseUrl}/api/w/${workspace}/users/list`;
7
  const response = await fetch(url, {
8
    headers: {
9
      Authorization: "Bearer " + Deno.env.get("WM_TOKEN") || "",
10
    },
11
  });
12

13
  if (response.statusText.toUpperCase() != "OK") {
14
    let errorMsg: string;
15
    if (response.headers.get("Content-Type")?.includes("json")) {
16
      errorMsg = await response.json();
17
    } else {
18
      errorMsg = await response.text();
19
    }
20
    throw new Error(`${response.status} ${response.statusText}: ${errorMsg}`);
21
  }
22
  const jsonData = await response.json();
23
  return jsonData;
24
}
25