Edits history of script submission #22582 for ' List Users (windmill)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    import * as wmill from "windmill-client"
    
    // windmill-client errors only carry the status text: throw the response body, which says why
    wmill.OpenAPI.interceptors.response.use(async (response) => {
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
      return response
    })
    
    /**
     * List Users
     * List the users of the workspace with their roles and groups. Requires a workspace admin.
     */
    export async function main() {
      return await wmill.UserService.listUsers({
        workspace: wmill.getWorkspace(),
      })
    }
    

    Submitted by hugo989 5 hours ago

  • bunnative
    //native
    
    export async function main() {
      const workspace = Bun.env.WM_WORKSPACE;
      const baseUrl = Bun.env.WM_BASE_URL;
      const url = `${baseUrl}/api/w/${workspace}/users/list`;
      const response = await fetch(url, {
        headers: {
          Authorization: "Bearer " + Bun.env.WM_TOKEN || "",
        },
      });
    
      if (response.statusText.toUpperCase() != "OK") {
        let errorMsg: string;
        if (response.headers.get("Content-Type")?.includes("json")) {
          errorMsg = await response.json();
        } else {
          errorMsg = await response.text();
        }
        throw new Error(`${response.status} ${response.statusText}: ${errorMsg}`);
      }
      const jsonData = await response.json();
      return jsonData;
    }
    

    Submitted by hugo989 134 days ago