0

Get list of users from current workspace

by
Published Sep 1, 2023

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

Script windmill Verified

The script

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

3
export async function main() {
4
  const workspace = Bun.env.WM_WORKSPACE;
5
  const baseUrl = Bun.env.WM_BASE_URL;
6
  const url = `${baseUrl}/api/w/${workspace}/users/list`;
7
  const response = await fetch(url, {
8
    headers: {
9
      Authorization: "Bearer " + Bun.env.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

Other submissions
  • Submitted by sindre svendby964 Deno
    Created 961 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