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

A specific, existing project can be deleted by making a DELETE request on the URL for that project.

Returns an empty data record.

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

9
Returns an empty data record.
10
 */
11
export async function main(
12
  auth: Asana,
13
  project_gid: string,
14
  opt_pretty: string | undefined,
15
  opt_fields: string | undefined
16
) {
17
  const url = new URL(`https://app.asana.com/api/1.0/projects/${project_gid}`);
18
  for (const [k, v] of [
19
    ["opt_pretty", opt_pretty],
20
    ["opt_fields", opt_fields],
21
  ]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "DELETE",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39