Get multiple portfolios

Returns a list of the portfolios in compact representation that are owned by the current API user.

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
 * Get multiple portfolios
6
 * Returns a list of the portfolios in compact representation that are owned by the current API user.
7
 */
8
export async function main(
9
  auth: Asana,
10
  opt_pretty: string | undefined,
11
  opt_fields: string | undefined,
12
  limit: string | undefined,
13
  offset: string | undefined,
14
  workspace: string | undefined,
15
  owner: string | undefined
16
) {
17
  const url = new URL(`https://app.asana.com/api/1.0/portfolios`);
18
  for (const [k, v] of [
19
    ["opt_pretty", opt_pretty],
20
    ["opt_fields", opt_fields],
21
    ["limit", limit],
22
    ["offset", offset],
23
    ["workspace", workspace],
24
    ["owner", owner],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43