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