0

Create Task Comment

by
Published Oct 17, 2025

Add a new comment to a task.

Script clickup Verified

The script

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