1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates employees |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | Xero_Tenant_Id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | employeeID?: string |
15 | title: string |
16 | firstName: string |
17 | lastName: string |
18 | dateOfBirth: string |
19 | address: { |
20 | addressLine1: string |
21 | addressLine2?: string |
22 | city: string |
23 | postCode: string |
24 | countryName?: string |
25 | } |
26 | email?: string |
27 | gender: 'M' | 'F' |
28 | phoneNumber?: string |
29 | startDate?: string |
30 | endDate?: string |
31 | payrollCalendarID?: string |
32 | updatedDateUTC?: string |
33 | createdDateUTC?: string |
34 | nationalInsuranceNumber?: string |
35 | isOffPayrollWorker?: false | true |
36 | } |
37 | ) { |
38 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees`) |
39 |
|
40 | const response = await fetch(url, { |
41 | method: 'POST', |
42 | headers: { |
43 | Accept: 'application/json', |
44 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
45 | 'Idempotency-Key': Idempotency_Key, |
46 | 'Content-Type': 'application/json', |
47 | Authorization: 'Bearer ' + auth.token |
48 | }, |
49 | body: JSON.stringify(body) |
50 | }) |
51 | if (!response.ok) { |
52 | const text = await response.text() |
53 | throw new Error(`${response.status} ${text}`) |
54 | } |
55 | return await response.json() |
56 | } |
57 |
|