Delete a tag

A specific, existing tag can be deleted by making a DELETE request on the URL for that tag. Returns an empty data record.

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

9
Returns an empty data record.
10
 */
11
export async function main(
12
  auth: Asana,
13
  tag_gid: string,
14
  opt_pretty: string | undefined,
15
  opt_fields: string | undefined,
16
  limit: string | undefined,
17
  offset: string | undefined
18
) {
19
  const url = new URL(`https://app.asana.com/api/1.0/tags/${tag_gid}`);
20
  for (const [k, v] of [
21
    ["opt_pretty", opt_pretty],
22
    ["opt_fields", opt_fields],
23
    ["limit", limit],
24
    ["offset", offset],
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