Delete a story

Deletes a story. A user can only delete stories they have created. Returns an empty data record.

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
 * Delete a story
6
 * Deletes a story. A user can only delete stories they have created.
7

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