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