1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates an employment detail for a specific employee |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | EmployeeID: string, |
12 | Xero_Tenant_Id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | payrollCalendarID: string |
16 | payRunCalendarID?: string |
17 | startDate: string |
18 | engagementType: string |
19 | fixedTermEndDate?: string |
20 | } |
21 | ) { |
22 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/Employment`) |
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 |
|