0

Remove Project from Task

by
Published Oct 31, 2023

Remove a task from a project. The task itself is kept.

Script asana Verified

The script

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

3
/**
4
 * Remove Project from Task
5
 * Remove a task from a project. The task itself is kept.
6
 */
7
export async function main(auth: RT.Asana, task_gid: string, project: string) {
8
  const response = await fetch(
9
    `https://app.asana.com/api/1.0/tasks/${task_gid}/removeProject`,
10
    {
11
      method: "POST",
12
      headers: {
13
        Authorization: `Bearer ${auth.token}`,
14
        "Content-Type": "application/json",
15
        Accept: "application/json",
16
      },
17
      body: JSON.stringify({ data: { project } }),
18
    }
19
  )
20

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

25
  return await response.json()
26
}
27

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 days ago
    1
    type Asana = {
    2
      token: string;
    3
    };
    4
    /**
    5
     * Remove a project from a task
    6
     * Removes the task from the specified project. The task will still exist in
    7
    the system, but it will not be in the project anymore.
    8
    
    
    9
    Returns an empty data block.
    10
     */
    11
    export async function main(
    12
      auth: Asana,
    13
      task_gid: string,
    14
      opt_pretty: string | undefined,
    15
      opt_fields: string | undefined,
    16
      body: {
    17
        data?: { project: string; [k: string]: unknown };
    18
        [k: string]: unknown;
    19
      }
    20
    ) {
    21
      const url = new URL(
    22
        `https://app.asana.com/api/1.0/tasks/${task_gid}/removeProject`
    23
      );
    24
      for (const [k, v] of [
    25
        ["opt_pretty", opt_pretty],
    26
        ["opt_fields", opt_fields],
    27
      ]) {
    28
        if (v !== undefined && v !== "") {
    29
          url.searchParams.append(k, v);
    30
        }
    31
      }
    32
      const response = await fetch(url, {
    33
        method: "POST",
    34
        headers: {
    35
          "Content-Type": "application/json",
    36
          Authorization: "Bearer " + auth.token,
    37
        },
    38
        body: JSON.stringify(body),
    39
      });
    40
      if (!response.ok) {
    41
        const text = await response.text();
    42
        throw new Error(`${response.status} ${text}`);
    43
      }
    44
      return await response.json();
    45
    }
    46