1 | |
2 | |
3 | * Create a timesheet entry |
4 | * Submit work for a contractor. |
5 | **Token scopes**: `timesheets:write` |
6 | */ |
7 | export async function main(auth: RT.Deel, body: Body) { |
8 | const url = new URL(`https://api.letsdeel.com/rest/v2/timesheets`) |
9 |
|
10 | const formData = new FormData() |
11 | for (const [k, v] of Object.entries(body)) { |
12 | if (v !== undefined && v !== '') { |
13 | formData.append(k, String(v)) |
14 | } |
15 | } |
16 | const response = await fetch(url, { |
17 | method: 'POST', |
18 | headers: { |
19 | 'Content-Type': 'application/json', |
20 | Authorization: 'Bearer ' + auth.apiKey |
21 | }, |
22 | body: JSON.stringify(body) |
23 | }) |
24 | if (!response.ok) { |
25 | const text = await response.text() |
26 | throw new Error(`${response.status} ${text}`) |
27 | } |
28 | return await response.json() |
29 | } |
30 |
|
31 | |
32 | |
33 | * This file was automatically generated by json-schema-to-typescript. |
34 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
35 | * and run json-schema-to-typescript to regenerate this file. |
36 | */ |
37 |
|
38 | export interface Body { |
39 | |
40 | * Details of the timesheet to create. Both a client or a contractor may create a timesheet. |
41 | */ |
42 | data: { |
43 | |
44 | * This is based on the scale of work statement of the associated contract |
45 | */ |
46 | quantity: number |
47 | |
48 | * Id of a Deel contract. |
49 | */ |
50 | contract_id: string |
51 | description: string |
52 | |
53 | * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31. |
54 | */ |
55 | date_submitted: string |
56 | |
57 | * If true, the timesheet will be automatically approved as part of the request. |
58 | */ |
59 | is_auto_approved?: boolean |
60 | |
61 | * Id of an existing timesheets preset. Created through /rest/v2/timesheets/presets |
62 | */ |
63 | hourly_report_preset_id?: string |
64 | [k: string]: unknown |
65 | } |
66 | [k: string]: unknown |
67 | } |
68 |
|