0
Remove a collaborator from a goal
One script reply has been approved by the moderators Verified

Removes followers from a goal. Returns the goal the followers were removed from. Each goal can be associated with zero or more followers in the system. Requests to add/remove followers, if successful, will return the complete updated goal record, described above.

Created by hugo697 313 days ago Viewed 8956 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 313 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Remove a collaborator from a goal
6
 * Removes followers from a goal. Returns the goal the followers were removed from.
7
Each goal can be associated with zero or more followers in the system.
8
Requests to add/remove followers, if successful, will return the complete updated goal record, described above.
9
 */
10
export async function main(
11
  auth: Asana,
12
  goal_gid: string,
13
  opt_pretty: string | undefined,
14
  opt_fields: string | undefined,
15
  body: {
16
    data?: { followers: string[]; [k: string]: unknown };
17
    [k: string]: unknown;
18
  }
19
) {
20
  const url = new URL(
21
    `https://app.asana.com/api/1.0/goals/${goal_gid}/removeFollowers`
22
  );
23
  for (const [k, v] of [
24
    ["opt_pretty", opt_pretty],
25
    ["opt_fields", opt_fields],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45