Create a status update

Creates a new status update on an object. Returns the full record of the newly created 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 status update
6
 * Creates a new status update on an object.
7
Returns the full record of the newly created status update.
8
 */
9
export async function main(
10
  auth: Asana,
11
  opt_pretty: string | undefined,
12
  opt_fields: string | undefined,
13
  limit: string | undefined,
14
  offset: string | undefined,
15
  body: {
16
    data?: (({ gid?: string; resource_type?: string; [k: string]: unknown } & {
17
      resource_subtype?:
18
        | "project_status_update"
19
        | "portfolio_status_update"
20
        | "goal_status_update";
21
      title?: string;
22
      [k: string]: unknown;
23
    }) & {
24
      html_text?: string;
25
      status_type:
26
        | "on_track"
27
        | "at_risk"
28
        | "off_track"
29
        | "on_hold"
30
        | "complete"
31
        | "achieved"
32
        | "partial"
33
        | "missed"
34
        | "dropped";
35
      text: string;
36
      [k: string]: unknown;
37
    }) & { parent: string; [k: string]: unknown };
38
    [k: string]: unknown;
39
  }
40
) {
41
  const url = new URL(`https://app.asana.com/api/1.0/status_updates`);
42
  for (const [k, v] of [
43
    ["opt_pretty", opt_pretty],
44
    ["opt_fields", opt_fields],
45
    ["limit", limit],
46
    ["offset", offset],
47
  ]) {
48
    if (v !== undefined && v !== "") {
49
      url.searchParams.append(k, v);
50
    }
51
  }
52
  const response = await fetch(url, {
53
    method: "POST",
54
    headers: {
55
      "Content-Type": "application/json",
56
      Authorization: "Bearer " + auth.token,
57
    },
58
    body: JSON.stringify(body),
59
  });
60
  if (!response.ok) {
61
    const text = await response.text();
62
    throw new Error(`${response.status} ${text}`);
63
  }
64
  return await response.json();
65
}
66