Create Task
One script reply has been approved by the moderators Verified

Create a new task.

Created by hugo697 168 days ago Picked 8 times
Submitted by hugo697 Bun
Verified 168 days ago
1
//native
2
type Clickup = {
3
  token: string;
4
};
5
/**
6
 * Create Task
7
 * Create a new task.
8
 */
9
export async function main(
10
  auth: Clickup,
11
  list_id: string,
12
  custom_task_ids: string | undefined,
13
  team_id: string | undefined,
14
  body: {
15
    name: string;
16
    description?: string;
17
    assignees?: number[];
18
    archived?: false | true;
19
    group_assignees?: string[];
20
    tags?: string[];
21
    status?: string;
22
    priority?: number;
23
    due_date?: number;
24
    due_date_time?: false | true;
25
    time_estimate?: number;
26
    start_date?: number;
27
    start_date_time?: false | true;
28
    points?: number;
29
    notify_all?: false | true;
30
    parent?: string;
31
    markdown_content?: string;
32
    links_to?: string;
33
    check_required_custom_fields?: false | true;
34
    custom_fields?: { id: string; value: string | number }[];
35
    custom_item_id?: number;
36
  },
37
) {
38
  const url = new URL(`https://api.clickup.com/api/v2/list/${list_id}/task`);
39
  for (const [k, v] of [
40
    ["custom_task_ids", custom_task_ids],
41
    ["team_id", team_id],
42
  ]) {
43
    if (v !== undefined && v !== "" && k !== undefined) {
44
      url.searchParams.append(k, v);
45
    }
46
  }
47
  const response = await fetch(url, {
48
    method: "POST",
49
    headers: {
50
      "Content-Type": "application/json",
51
      Authorization: auth.token,
52
    },
53
    body: JSON.stringify(body),
54
  });
55
  if (!response.ok) {
56
    const text = await response.text();
57
    throw new Error(`${response.status} ${text}`);
58
  }
59
  return await response.json();
60
}
61