Update a story

Updates the story and returns the full record for the updated story. Only comment stories can have their text updated, and only comment stories and attachment stories can be pinned. Only one of `text` and `html_text` can be specified.

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
 * Update a story
6
 * Updates the story and returns the full record for the updated story. Only comment stories can have their text updated, and only comment stories and attachment stories can be pinned. Only one of `text` and `html_text` can be specified.
7
 */
8
export async function main(
9
  auth: Asana,
10
  story_gid: string,
11
  opt_pretty: string | undefined,
12
  opt_fields: string | undefined,
13
  body: {
14
    data?: { gid?: string; resource_type?: string; [k: string]: unknown } & {
15
      created_at?: string;
16
      html_text?: string;
17
      is_pinned?: boolean;
18
      resource_subtype?: string;
19
      sticker_name?:
20
        | "green_checkmark"
21
        | "people_dancing"
22
        | "dancing_unicorn"
23
        | "heart"
24
        | "party_popper"
25
        | "people_waving_flags"
26
        | "splashing_narwhal"
27
        | "trophy"
28
        | "yeti_riding_unicorn"
29
        | "celebrating_people"
30
        | "determined_climbers"
31
        | "phoenix_spreading_love";
32
      text?: string;
33
      [k: string]: unknown;
34
    };
35
    [k: string]: unknown;
36
  }
37
) {
38
  const url = new URL(`https://app.asana.com/api/1.0/stories/${story_gid}`);
39
  for (const [k, v] of [
40
    ["opt_pretty", opt_pretty],
41
    ["opt_fields", opt_fields],
42
  ]) {
43
    if (v !== undefined && v !== "") {
44
      url.searchParams.append(k, v);
45
    }
46
  }
47
  const response = await fetch(url, {
48
    method: "PUT",
49
    headers: {
50
      "Content-Type": "application/json",
51
      Authorization: "Bearer " + auth.token,
52
    },
53
    body: JSON.stringify(body),
54
  });
55
  if (!response.ok) {
56
    const text = await response.text();
57
    throw new Error(`${response.status} ${text}`);
58
  }
59
  return await response.json();
60
}
61