Track time
One script reply has been approved by the moderators Verified

Note: This is a legacy time tracking endpoint. We recommend using the Time Tracking API endpoints to manage time entries.

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
 * Track time
7
 * ***Note:** This is a legacy time tracking endpoint. We recommend using the Time Tracking API endpoints to manage time entries.*
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: { start: number; end: number; time: number },
15
) {
16
  const url = new URL(`https://api.clickup.com/api/v2/task/${task_id}/time`);
17
  for (const [k, v] of [
18
    ["custom_task_ids", custom_task_ids],
19
    ["team_id", team_id],
20
  ]) {
21
    if (v !== undefined && v !== "" && k !== undefined) {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39