Remove a user from a workspace or organization

Remove a user from a workspace or organization. The user making this call must be an admin in the workspace. The user can be referenced by their globally unique user ID or their email address. Returns an empty data record.

Script asana Verified

by hugo697 ยท 10/31/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Remove a user from a workspace or organization
6
 * Remove a user from a workspace or organization.
7
The user making this call must be an admin in the workspace. The user can be referenced by their globally unique user ID or their email address.
8
Returns an empty data record.
9
 */
10
export async function main(
11
  auth: Asana,
12
  workspace_gid: string,
13
  opt_pretty: string | undefined,
14
  opt_fields: string | undefined,
15
  body: { data?: { user?: string; [k: string]: unknown }; [k: string]: unknown }
16
) {
17
  const url = new URL(
18
    `https://app.asana.com/api/1.0/workspaces/${workspace_gid}/removeUser`
19
  );
20
  for (const [k, v] of [
21
    ["opt_pretty", opt_pretty],
22
    ["opt_fields", opt_fields],
23
  ]) {
24
    if (v !== undefined && v !== "") {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42