Edit time tracked
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
 * Edit time tracked
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
  interval_id: string,
13
  custom_task_ids: string | undefined,
14
  team_id: string | undefined,
15
  body: { start: number; end: number; time: number },
16
) {
17
  const url = new URL(
18
    `https://api.clickup.com/api/v2/task/${task_id}/time/${interval_id}`,
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: "PUT",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: auth.token,
33
    },
34
    body: JSON.stringify(body),
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