0

Get users in a workspace or organization

by
Published Oct 31, 2023

Returns the compact records for all users in the specified workspace or organization. Results are sorted alphabetically and limited to 2000. For more results use the `/users` endpoint.

Script asana Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 403 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get users in a workspace or organization
6
 * Returns the compact records for all users in the specified workspace or organization.
7
Results are sorted alphabetically and limited to 2000. For more results use the `/users` endpoint.
8
 */
9
export async function main(
10
  auth: Asana,
11
  workspace_gid: string,
12
  opt_pretty: string | undefined,
13
  opt_fields: string | undefined,
14
  offset: string | undefined
15
) {
16
  const url = new URL(
17
    `https://app.asana.com/api/1.0/workspaces/${workspace_gid}/users`
18
  );
19
  for (const [k, v] of [
20
    ["opt_pretty", opt_pretty],
21
    ["opt_fields", opt_fields],
22
    ["offset", offset],
23
  ]) {
24
    if (v !== undefined && v !== "") {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41