0
Get a project status
One script reply has been approved by the moderators Verified

Deprecated: new integrations should prefer the /status_updates/{status_gid} route.

Returns the complete record for a single status update.

Created by hugo697 202 days ago Viewed 6886 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 202 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get a project status
6
 * *Deprecated: new integrations should prefer the `/status_updates/{status_gid}` route.*
7

8
Returns the complete record for a single status update.
9
 */
10
export async function main(
11
  auth: Asana,
12
  project_status_gid: string,
13
  opt_pretty: string | undefined,
14
  opt_fields: string | undefined
15
) {
16
  const url = new URL(
17
    `https://app.asana.com/api/1.0/project_statuses/${project_status_gid}`
18
  );
19
  for (const [k, v] of [
20
    ["opt_pretty", opt_pretty],
21
    ["opt_fields", opt_fields],
22
  ]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
29
    headers: {
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40