Update a tag

Updates the properties of a tag. Only the fields provided in the `data` block will be updated; any unspecified fields will remain unchanged. When using this method, it is best to specify only those fields you wish to change, or else you may overwrite changes made by another user since you last retrieved the tag. Returns the complete updated tag 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
 * Update a tag
6
 * Updates the properties of a tag. Only the fields provided in the `data`
7
block will be updated; any unspecified fields will remain unchanged.
8

9
When using this method, it is best to specify only those fields you wish
10
to change, or else you may overwrite changes made by another user since
11
you last retrieved the tag.
12

13
Returns the complete updated tag record.
14
 */
15
export async function main(
16
  auth: Asana,
17
  tag_gid: string,
18
  opt_pretty: string | undefined,
19
  opt_fields: string | undefined,
20
  limit: string | undefined,
21
  offset: string | undefined
22
) {
23
  const url = new URL(`https://app.asana.com/api/1.0/tags/${tag_gid}`);
24
  for (const [k, v] of [
25
    ["opt_pretty", opt_pretty],
26
    ["opt_fields", opt_fields],
27
    ["limit", limit],
28
    ["offset", offset],
29
  ]) {
30
    if (v !== undefined && v !== "") {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "PUT",
36
    headers: {
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47