0
Get multiple portfolio memberships
One script reply has been approved by the moderators Verified

Returns a list of portfolio memberships in compact representation. You must specify portfolio, portfolio and user, or workspace and user.

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