1 | |
2 | type Xero = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Creates a leave application |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | Xero_Tenant_Id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | LeaveApplicationID?: string; |
15 | EmployeeID?: string; |
16 | LeaveTypeID?: string; |
17 | Title?: string; |
18 | StartDate?: string; |
19 | EndDate?: string; |
20 | Description?: string; |
21 | PayOutType?: "DEFAULT" | "CASHED_OUT"; |
22 | LeavePeriods?: { |
23 | NumberOfUnits?: number; |
24 | PayPeriodEndDate?: string; |
25 | PayPeriodStartDate?: string; |
26 | LeavePeriodStatus?: "SCHEDULED" | "PROCESSED" | "REQUESTED" | "REJECTED"; |
27 | }[]; |
28 | UpdatedDateUTC?: string; |
29 | ValidationErrors?: { Message?: string }[]; |
30 | }[], |
31 | ) { |
32 | const url = new URL(`https://api.xero.com/payroll.xro/1.0/LeaveApplications`); |
33 |
|
34 | const response = await fetch(url, { |
35 | method: "POST", |
36 | headers: { |
37 | Accept: 'application/json', |
38 | "Xero-Tenant-Id": Xero_Tenant_Id, |
39 | "Idempotency-Key": Idempotency_Key, |
40 | "Content-Type": "application/json", |
41 | Authorization: "Bearer " + auth.token, |
42 | }, |
43 | body: JSON.stringify(body), |
44 | }); |
45 | if (!response.ok) { |
46 | const text = await response.text(); |
47 | throw new Error(`${response.status} ${text}`); |
48 | } |
49 | return await response.json(); |
50 | } |
51 |
|