1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List time entries. |
7 | * List all time entries with pagination. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | from_date: string | undefined, |
13 | to_date: string | undefined, |
14 | filter_by: string | undefined, |
15 | project_id: string | undefined, |
16 | user_id: string | undefined, |
17 | sort_column: string | undefined, |
18 | ) { |
19 | const url = new URL(`https://www.zohoapis.com/books/v3/projects/timeentries`); |
20 | for (const [k, v] of [ |
21 | ["organization_id", organization_id], |
22 | ["from_date", from_date], |
23 | ["to_date", to_date], |
24 | ["filter_by", filter_by], |
25 | ["project_id", project_id], |
26 | ["user_id", user_id], |
27 | ["sort_column", sort_column], |
28 | ]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "GET", |
35 | headers: { |
36 | Authorization: "Zoho-oauthtoken " + auth.token, |
37 | }, |
38 | body: undefined, |
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 |
|