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

Removes the specified list of users from members of the project. Returns the updated project record.

Created by hugo697 201 days ago Viewed 6772 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 201 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Remove users from a project
6
 * Removes the specified list of users from members of the project.
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?: { members: 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}/removeMembers`
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