0
Remove a user from a team
One script reply has been approved by the moderators Verified

The user making this call must be a member of the team in order to remove themselves or others.

Created by hugo697 191 days ago Viewed 5921 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 191 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Remove a user from a team
6
 * The user making this call must be a member of the team in order to remove themselves or others.
7
 */
8
export async function main(
9
  auth: Asana,
10
  team_gid: string,
11
  opt_pretty: string | undefined,
12
  opt_fields: string | undefined,
13
  body: { data?: { user?: string; [k: string]: unknown }; [k: string]: unknown }
14
) {
15
  const url = new URL(
16
    `https://app.asana.com/api/1.0/teams/${team_gid}/removeUser`
17
  );
18
  for (const [k, v] of [
19
    ["opt_pretty", opt_pretty],
20
    ["opt_fields", opt_fields],
21
  ]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "POST",
28
    headers: {
29
      "Content-Type": "application/json",
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40