0

Update project time

by
Published Oct 17, 2025

Update a specific time tracking. Only the params included in the operation will update the time tracking.

Script holded Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Holded = {
3
  apiKey: string;
4
};
5
/**
6
 * Update project time
7
 * Update a specific time tracking.
8

9
Only the params included in the operation will update the time tracking.
10
 */
11
export async function main(
12
  auth: Holded,
13
  projectId: string,
14
  timeTrackingId: string,
15
  body: {
16
    duration: number;
17
    desc?: string;
18
    costHour: number;
19
    userId?: string;
20
    taskId?: string;
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.holded.com/api/projects/v1/projects/${projectId}/times/${timeTrackingId}`,
25
  );
26

27
  const response = await fetch(url, {
28
    method: "PUT",
29
    headers: {
30
      "Content-Type": "application/json",
31
      key: auth.apiKey,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41