0

Delete Task

by
Published Oct 31, 2023

Delete a task. It moves to the trash of the user who ran the deletion and can be recovered from there for 30 days.

Script asana Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * Delete Task
5
 * Delete a task. It moves to the trash of the user who ran the deletion and can be recovered from there for 30 days.
6
 */
7
export async function main(auth: RT.Asana, task_gid: string) {
8
  const response = await fetch(
9
    `https://app.asana.com/api/1.0/tasks/${task_gid}`,
10
    {
11
      method: "DELETE",
12
      headers: {
13
        Authorization: `Bearer ${auth.token}`,
14
        Accept: "application/json",
15
      },
16
    }
17
  )
18

19
  if (!response.ok) {
20
    throw new Error(`${response.status} ${await response.text()}`)
21
  }
22

23
  return await response.json()
24
}
25

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 days ago
    1
    type Asana = {
    2
      token: string;
    3
    };
    4
    /**
    5
     * Delete a task
    6
     * A specific, existing task can be deleted by making a DELETE request on
    7
    the URL for that task. Deleted tasks go into the “trash” of the user
    8
    making the delete request. Tasks can be recovered from the trash within a
    9
    period of 30 days; afterward they are completely removed from the system.
    10
    
    
    11
    Returns an empty data record.
    12
     */
    13
    export async function main(
    14
      auth: Asana,
    15
      task_gid: string,
    16
      opt_pretty: string | undefined,
    17
      opt_fields: string | undefined
    18
    ) {
    19
      const url = new URL(`https://app.asana.com/api/1.0/tasks/${task_gid}`);
    20
      for (const [k, v] of [
    21
        ["opt_pretty", opt_pretty],
    22
        ["opt_fields", opt_fields],
    23
      ]) {
    24
        if (v !== undefined && v !== "") {
    25
          url.searchParams.append(k, v);
    26
        }
    27
      }
    28
      const response = await fetch(url, {
    29
        method: "DELETE",
    30
        headers: {
    31
          Authorization: "Bearer " + auth.token,
    32
        },
    33
        body: undefined,
    34
      });
    35
      if (!response.ok) {
    36
        const text = await response.text();
    37
        throw new Error(`${response.status} ${text}`);
    38
      }
    39
      return await response.json();
    40
    }
    41