1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates opening balances 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 | periodEndDate?: string |
16 | daysPaid?: number |
17 | unpaidWeeks?: number |
18 | grossEarnings?: number |
19 | }[] |
20 | ) { |
21 | const url = new URL( |
22 | `https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/OpeningBalances` |
23 | ) |
24 |
|
25 | const response = await fetch(url, { |
26 | method: 'POST', |
27 | headers: { |
28 | Accept: 'application/json', |
29 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
30 | 'Idempotency-Key': Idempotency_Key, |
31 | 'Content-Type': 'application/json', |
32 | Authorization: 'Bearer ' + auth.token |
33 | }, |
34 | body: JSON.stringify(body) |
35 | }) |
36 | if (!response.ok) { |
37 | const text = await response.text() |
38 | throw new Error(`${response.status} ${text}`) |
39 | } |
40 | return await response.json() |
41 | } |
42 |
|