Add Tag To Task
One script reply has been approved by the moderators Verified

Add a Tag to a task.

Created by hugo697 168 days ago
Submitted by hugo697 Bun
Verified 168 days ago
1
//native
2
type Clickup = {
3
  token: string;
4
};
5
/**
6
 * Add Tag To Task
7
 * Add a Tag to a task.
8
 */
9
export async function main(
10
  auth: Clickup,
11
  task_id: string,
12
  tag_name: string,
13
  custom_task_ids: string | undefined,
14
  team_id: string | undefined,
15
  Content_Type: string,
16
) {
17
  const url = new URL(
18
    `https://api.clickup.com/api/v2/task/${task_id}/tag/${tag_name}`,
19
  );
20
  for (const [k, v] of [
21
    ["custom_task_ids", custom_task_ids],
22
    ["team_id", team_id],
23
  ]) {
24
    if (v !== undefined && v !== "" && k !== undefined ) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": Content_Type,
32
      Authorization: auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42