0
Get a team's projects
One script reply has been approved by the moderators Verified

Returns the compact project records for all projects in the team.

Created by hugo697 203 days ago Viewed 6944 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 203 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get a team's projects
6
 * Returns the compact project records for all projects in the team.
7
 */
8
export async function main(
9
  auth: Asana,
10
  team_gid: string,
11
  opt_pretty: string | undefined,
12
  opt_fields: string | undefined,
13
  limit: string | undefined,
14
  offset: string | undefined,
15
  archived: string | undefined
16
) {
17
  const url = new URL(
18
    `https://app.asana.com/api/1.0/teams/${team_gid}/projects`
19
  );
20
  for (const [k, v] of [
21
    ["opt_pretty", opt_pretty],
22
    ["opt_fields", opt_fields],
23
    ["limit", limit],
24
    ["offset", offset],
25
    ["archived", archived],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44