Create a time entry
One script reply has been approved by the moderators Verified

Create a time entry.

Note: A time entry that has a negative duration means that timer is currently running for that user.

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