1 | |
2 | type Holded = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * List Documents |
7 | * Get all your documents by type. |
8 | */ |
9 | export async function main( |
10 | auth: Holded, |
11 | docType: string, |
12 | starttmp: string | undefined, |
13 | endtmp: string | undefined, |
14 | contactid: string | undefined, |
15 | paid: string | undefined, |
16 | billed: string | undefined, |
17 | sort: string | undefined, |
18 | ) { |
19 | const url = new URL( |
20 | `https://api.holded.com/api/invoicing/v1/documents/${docType}`, |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["starttmp", starttmp], |
24 | ["endtmp", endtmp], |
25 | ["contactid", contactid], |
26 | ["paid", paid], |
27 | ["billed", billed], |
28 | ["sort", sort], |
29 | ]) { |
30 | if (v !== undefined && v !== "" && k !== undefined) { |
31 | url.searchParams.append(k, v); |
32 | } |
33 | } |
34 | const response = await fetch(url, { |
35 | method: "GET", |
36 | headers: { |
37 | key: auth.apiKey, |
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 |
|