1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Retrieves payslips |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | page: string | undefined, |
12 | PayRunID: string | undefined, |
13 | Xero_Tenant_Id: string |
14 | ) { |
15 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Payslips`) |
16 | for (const [k, v] of [ |
17 | ['page', page], |
18 | ['PayRunID', PayRunID] |
19 | ]) { |
20 | if (v !== undefined && v !== '' && k !== undefined) { |
21 | url.searchParams.append(k, v) |
22 | } |
23 | } |
24 | const response = await fetch(url, { |
25 | method: 'GET', |
26 | headers: { |
27 | Accept: 'application/json', |
28 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
29 | Authorization: 'Bearer ' + auth.token |
30 | }, |
31 | body: undefined |
32 | }) |
33 | if (!response.ok) { |
34 | const text = await response.text() |
35 | throw new Error(`${response.status} ${text}`) |
36 | } |
37 | return await response.json() |
38 | } |
39 |
|