Create a project status

*Deprecated: new integrations should prefer the `/status_updates` route.* Creates a new status update on the project. Returns the full record of the newly created project status update.

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

8
Creates a new status update on the project.
9

10
Returns the full record of the newly created project status update.
11
 */
12
export async function main(
13
  auth: Asana,
14
  project_gid: string,
15
  opt_pretty: string | undefined,
16
  opt_fields: string | undefined,
17
  body: {
18
    data?: ({ gid?: string; resource_type?: string; [k: string]: unknown } & {
19
      title?: string;
20
      [k: string]: unknown;
21
    }) & {
22
      color: "green" | "yellow" | "red" | "blue";
23
      html_text?: string;
24
      text: string;
25
      [k: string]: unknown;
26
    };
27
    [k: string]: unknown;
28
  }
29
) {
30
  const url = new URL(
31
    `https://app.asana.com/api/1.0/projects/${project_gid}/project_statuses`
32
  );
33
  for (const [k, v] of [
34
    ["opt_pretty", opt_pretty],
35
    ["opt_fields", opt_fields],
36
  ]) {
37
    if (v !== undefined && v !== "") {
38
      url.searchParams.append(k, v);
39
    }
40
  }
41
  const response = await fetch(url, {
42
    method: "POST",
43
    headers: {
44
      "Content-Type": "application/json",
45
      Authorization: "Bearer " + auth.token,
46
    },
47
    body: JSON.stringify(body),
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55