1 | |
2 | type Codat = { |
3 | encodedKey: string |
4 | } |
5 | |
6 | * List create operations |
7 | * List create operations. |
8 | */ |
9 | export async function main( |
10 | auth: Codat, |
11 | companyId: string, |
12 | page: string | undefined, |
13 | pageSize: string | undefined, |
14 | query: string | undefined, |
15 | orderBy: string | undefined |
16 | ) { |
17 | const url = new URL(`https://api.codat.io/companies/${companyId}/push`) |
18 | for (const [k, v] of [ |
19 | ['page', page], |
20 | ['pageSize', pageSize], |
21 | ['query', query], |
22 | ['orderBy', orderBy] |
23 | ]) { |
24 | if (v !== undefined && v !== '' && k !== undefined) { |
25 | url.searchParams.append(k, v) |
26 | } |
27 | } |
28 |
|
29 | const response = await fetch(url, { |
30 | method: 'GET', |
31 | headers: { |
32 | Authorization: `Basic ${auth.encodedKey}` |
33 | }, |
34 | body: undefined |
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 |
|