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

An existing portfolio can be deleted by making a DELETE request on the URL for that portfolio.

Returns an empty data record.

Created by hugo697 418 days ago Viewed 9143 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 418 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Delete a portfolio
6
 * An existing portfolio can be deleted by making a DELETE request on
7
the URL for that portfolio.
8

9
Returns an empty data record.
10
 */
11
export async function main(
12
  auth: Asana,
13
  portfolio_gid: string,
14
  opt_pretty: string | undefined,
15
  opt_fields: string | undefined
16
) {
17
  const url = new URL(
18
    `https://app.asana.com/api/1.0/portfolios/${portfolio_gid}`
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: "DELETE",
30
    headers: {
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: undefined,
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