1 | |
2 | |
3 | * List of timesheets |
4 | * Retrieve a list of timesheets in your Deel account. You can filter the list by providing additional paramters e.g. contract_id, contract_type etc. |
5 | **Token scopes**: `timesheets:read` |
6 | */ |
7 | export async function main( |
8 | auth: RT.Deel, |
9 | contract_id?: string | undefined, |
10 | contract_types?: string | undefined, |
11 | statuses?: string | undefined, |
12 | reporter_id?: string | undefined, |
13 | date_from?: string | undefined, |
14 | date_to?: string | undefined, |
15 | limit?: string | undefined, |
16 | offset?: string | undefined |
17 | ) { |
18 | const url = new URL(`https://api.letsdeel.com/rest/v2/timesheets`) |
19 | for (const [k, v] of [ |
20 | ['contract_id', contract_id], |
21 | ['contract_types', contract_types], |
22 | ['statuses', statuses], |
23 | ['reporter_id', reporter_id], |
24 | ['date_from', date_from], |
25 | ['date_to', date_to], |
26 | ['limit', limit], |
27 | ['offset', offset] |
28 | ]) { |
29 | if (v !== undefined && v !== '') { |
30 | url.searchParams.append(k, v) |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: 'GET', |
35 | headers: { |
36 | Authorization: 'Bearer ' + auth.apiKey |
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 |
|