Update a time Entry
One script reply has been approved by the moderators Verified

Update the details of a time entry.

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
 * Update a time Entry
7
 * Update the details of a time entry.
8
 */
9
export async function main(
10
  auth: Clickup,
11
  team_id: string,
12
  timer_id: string,
13
  custom_task_ids: string | undefined,
14
  body: {
15
    description?: string;
16
    tags: { name: string; tag_fg: string; tag_bg: string }[];
17
    tag_action?: string;
18
    start?: number;
19
    end?: number;
20
    tid: string;
21
    billable?: false | true;
22
    duration?: number;
23
  },
24
) {
25
  const url = new URL(
26
    `https://api.clickup.com/api/v2/team/${team_id}/time_entries/${timer_id}`,
27
  );
28
  for (const [k, v] of [["custom_task_ids", custom_task_ids]]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "PUT",
35
    headers: {
36
      "Content-Type": "application/json",
37
      Authorization: auth.token,
38
    },
39
    body: JSON.stringify(body),
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47