0

Remove followers from a task

by
Published Oct 31, 2023

Removes each of the specified followers from the task if they are following. Returns the complete, updated record for the affected task.

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 followers from a task
6
 * Removes each of the specified followers from the task if they are following. Returns the complete, updated record for the affected task.
7
 */
8
export async function main(
9
  auth: Asana,
10
  task_gid: string,
11
  opt_pretty: string | undefined,
12
  opt_fields: string | undefined,
13
  body: {
14
    data?: { followers: string[]; [k: string]: unknown };
15
    [k: string]: unknown;
16
  }
17
) {
18
  const url = new URL(
19
    `https://app.asana.com/api/1.0/tasks/${task_gid}/removeFollowers`
20
  );
21
  for (const [k, v] of [
22
    ["opt_pretty", opt_pretty],
23
    ["opt_fields", opt_fields],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43