list all workspaces as super admin (require to be super admin)

Script windmill Verified

by admin ยท 8/13/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * list all workspaces as super admin (require to be super admin)
3
 *
4
 */
5
export async function main(
6
  page: string | undefined,
7
  per_page: string | undefined
8
) {
9
  const url = new URL(`${BASE_URL}/api/workspaces/list_as_superadmin`);
10
  for (const [k, v] of [
11
    ["page", page],
12
    ["per_page", per_page],
13
  ]) {
14
    if (v !== undefined && v !== "") {
15
      url.searchParams.append(k, v);
16
    }
17
  }
18
  const response = await fetch(url, {
19
    method: "GET",
20
    headers: {
21
      Authorization: "Bearer " + WM_TOKEN,
22
    },
23
    body: undefined,
24
  });
25
  if (!response.ok) {
26
    const text = await response.text();
27
    throw new Error(`${response.status} ${text}`);
28
  }
29
  return await response.json();
30
}
31