1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Log time entries |
7 | * Logging time entries. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | project_id: string; |
14 | task_id: string; |
15 | user_id: string; |
16 | log_date: string; |
17 | log_time?: string; |
18 | begin_time?: string; |
19 | end_time?: string; |
20 | is_billable?: false | true; |
21 | notes?: string; |
22 | start_timer?: string; |
23 | cost_rate?: number; |
24 | }, |
25 | ) { |
26 | const url = new URL(`https://www.zohoapis.com/books/v3/projects/timeentries`); |
27 | for (const [k, v] of [["organization_id", organization_id]]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "POST", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | Authorization: "Zoho-oauthtoken " + auth.token, |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|