0
Remove a portfolio item
One script reply has been approved by the moderators Verified

Remove an item from a portfolio. Returns an empty data block.

Created by hugo697 610 days ago Viewed 22469 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 610 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Remove a portfolio item
6
 * Remove an item from a portfolio.
7
Returns an empty data block.
8
 */
9
export async function main(
10
  auth: Asana,
11
  portfolio_gid: string,
12
  opt_pretty: string | undefined,
13
  opt_fields: string | undefined,
14
  body: { data?: { item: string; [k: string]: unknown }; [k: string]: unknown }
15
) {
16
  const url = new URL(
17
    `https://app.asana.com/api/1.0/portfolios/${portfolio_gid}/removeItem`
18
  );
19
  for (const [k, v] of [
20
    ["opt_pretty", opt_pretty],
21
    ["opt_fields", opt_fields],
22
  ]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41