0

Remove a project from a task

by
Published Oct 31, 2023

Removes the task from the specified project. The task will still exist in the system, but it will not be in the project anymore. Returns an empty data block.

Script asana Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 403 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