Get statuses from a project

*Deprecated: new integrations should prefer the `/status_updates` route.* Returns the compact project status update records for all updates on the project.

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 statuses from a project
6
 * *Deprecated: new integrations should prefer the `/status_updates` route.*
7

8
Returns the compact project status update records for all updates on the project.
9
 */
10
export async function main(
11
  auth: Asana,
12
  project_gid: string,
13
  opt_pretty: string | undefined,
14
  opt_fields: string | undefined,
15
  limit: string | undefined,
16
  offset: string | undefined
17
) {
18
  const url = new URL(
19
    `https://app.asana.com/api/1.0/projects/${project_gid}/project_statuses`
20
  );
21
  for (const [k, v] of [
22
    ["opt_pretty", opt_pretty],
23
    ["opt_fields", opt_fields],
24
    ["limit", limit],
25
    ["offset", offset],
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