Get users in a team

Returns the compact records for all users that are members of the team. Results are sorted alphabetically and limited to 2000. For more results use the `/users` endpoint.

Script asana Verified

by hugo697 ยท 10/31/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get users in a team
6
 * Returns the compact records for all users that are members of the team.
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
  team_gid: string,
12
  opt_pretty: string | undefined,
13
  opt_fields: string | undefined,
14
  offset: string | undefined
15
) {
16
  const url = new URL(`https://app.asana.com/api/1.0/teams/${team_gid}/users`);
17
  for (const [k, v] of [
18
    ["opt_pretty", opt_pretty],
19
    ["opt_fields", opt_fields],
20
    ["offset", offset],
21
  ]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39