1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates an earnings template records for an employee |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | EmployeeID: string, |
12 | PayTemplateEarningID: string, |
13 | Xero_Tenant_Id: string, |
14 | Idempotency_Key: string, |
15 | body: { |
16 | payTemplateEarningID?: string |
17 | ratePerUnit?: number |
18 | numberOfUnits?: number |
19 | fixedAmount?: number |
20 | earningsRateID?: string |
21 | name?: string |
22 | } |
23 | ) { |
24 | const url = new URL( |
25 | `https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/PayTemplates/Earnings/${PayTemplateEarningID}` |
26 | ) |
27 |
|
28 | const response = await fetch(url, { |
29 | method: 'PUT', |
30 | headers: { |
31 | Accept: 'application/json', |
32 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
33 | 'Idempotency-Key': Idempotency_Key, |
34 | 'Content-Type': 'application/json', |
35 | Authorization: 'Bearer ' + auth.token |
36 | }, |
37 | body: JSON.stringify(body) |
38 | }) |
39 | if (!response.ok) { |
40 | const text = await response.text() |
41 | throw new Error(`${response.status} ${text}`) |
42 | } |
43 | return await response.json() |
44 | } |
45 |
|