1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates a new timesheet line for a specific timesheet using a unique timesheet ID |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | TimesheetID: string, |
12 | Xero_Tenant_Id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | timesheetLineID?: string |
16 | date: string |
17 | earningsRateID: string |
18 | trackingItemID?: string |
19 | numberOfUnits: number |
20 | } |
21 | ) { |
22 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Timesheets/${TimesheetID}/Lines`) |
23 |
|
24 | const response = await fetch(url, { |
25 | method: 'POST', |
26 | headers: { |
27 | Accept: 'application/json', |
28 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
29 | 'Idempotency-Key': Idempotency_Key, |
30 | 'Content-Type': 'application/json', |
31 | Authorization: 'Bearer ' + auth.token |
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 |
|