Delete a section

A specific, existing section can be deleted by making a DELETE request on the URL for that section. Note that sections must be empty to be deleted. The last remaining section cannot be deleted. Returns an empty data block.

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
 * Delete a section
6
 * A specific, existing section can be deleted by making a DELETE request on
7
the URL for that section.
8

9
Note that sections must be empty to be deleted.
10

11
The last remaining section cannot be deleted.
12

13
Returns an empty data block.
14
 */
15
export async function main(
16
  auth: Asana,
17
  section_gid: string,
18
  opt_pretty: string | undefined,
19
  opt_fields: string | undefined
20
) {
21
  const url = new URL(`https://app.asana.com/api/1.0/sections/${section_gid}`);
22
  for (const [k, v] of [
23
    ["opt_pretty", opt_pretty],
24
    ["opt_fields", opt_fields],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "DELETE",
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