0
Remove followers from a project
One script reply has been approved by the moderators Verified

Removes the specified list of users from following the project, this will not affect project membership status. Returns the updated project record.

Created by hugo697 192 days ago Viewed 5952 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 192 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Remove followers from a project
6
 * Removes the specified list of users from following the project, this will not affect project membership status.
7
Returns the updated project record.
8
 */
9
export async function main(
10
  auth: Asana,
11
  project_gid: string,
12
  opt_pretty: string | undefined,
13
  opt_fields: string | undefined,
14
  body: {
15
    data?: { followers: string; [k: string]: unknown };
16
    [k: string]: unknown;
17
  }
18
) {
19
  const url = new URL(
20
    `https://app.asana.com/api/1.0/projects/${project_gid}/removeFollowers`
21
  );
22
  for (const [k, v] of [
23
    ["opt_pretty", opt_pretty],
24
    ["opt_fields", opt_fields],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44