0
Get the workspace memberships for a workspace
One script reply has been approved by the moderators Verified

Returns the compact workspace membership records for the workspace.

Created by hugo697 346 days ago Viewed 8991 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 346 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get the workspace memberships for a workspace
6
 * Returns the compact workspace membership records for the workspace.
7
 */
8
export async function main(
9
  auth: Asana,
10
  workspace_gid: string,
11
  user: string | undefined,
12
  opt_pretty: string | undefined,
13
  opt_fields: string | undefined,
14
  limit: string | undefined,
15
  offset: string | undefined
16
) {
17
  const url = new URL(
18
    `https://app.asana.com/api/1.0/workspaces/${workspace_gid}/workspace_memberships`
19
  );
20
  for (const [k, v] of [
21
    ["user", user],
22
    ["opt_pretty", opt_pretty],
23
    ["opt_fields", opt_fields],
24
    ["limit", limit],
25
    ["offset", offset],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
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