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