1 | |
2 | type Pandadoc = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Pandadoc, |
8 | count: string | undefined, |
9 | page: string | undefined, |
10 | status: string | undefined, |
11 | order_by: 'name' | 'responses' | 'status' | 'created_date' | 'modified_date' | undefined, |
12 | asc: string | undefined, |
13 | name: string | undefined |
14 | ) { |
15 | const url = new URL(`https://api.pandadoc.com/public/v1/forms`) |
16 |
|
17 | for (const [k, v] of [ |
18 | ['count', count], |
19 | ['page', page], |
20 | ['status', status], |
21 | ['order_by', order_by], |
22 | ['asc', asc], |
23 | ['name', name] |
24 | ]) { |
25 | if (v !== undefined && v !== '' && k !== undefined) { |
26 | url.searchParams.append(k, v) |
27 | } |
28 | } |
29 |
|
30 | const response = await fetch(url, { |
31 | method: 'GET', |
32 | headers: { |
33 | Authorization: `API-Key ${auth.apiKey}` |
34 | }, |
35 | body: undefined |
36 | }) |
37 |
|
38 | if (!response.ok) { |
39 | const text = await response.text() |
40 | throw new Error(`${response.status} ${text}`) |
41 | } |
42 |
|
43 | return await response.json() |
44 | } |
45 |
|