1 | |
2 | type Docspring = { |
3 | tokenId: string |
4 | tokenSecret: string |
5 | } |
6 | |
7 | * List all submissions |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Docspring, |
12 | cursor: string | undefined, |
13 | limit: string | undefined, |
14 | created_after: string | undefined, |
15 | created_before: string | undefined, |
16 | type: string | undefined, |
17 | include_data: string | undefined |
18 | ) { |
19 | const url = new URL(`https://api.docspring.com/api/v1/submissions`) |
20 |
|
21 | const token = btoa(auth.tokenId + ':' + auth.tokenSecret) |
22 |
|
23 | for (const [k, v] of [ |
24 | ['cursor', cursor], |
25 | ['limit', limit], |
26 | ['created_after', created_after], |
27 | ['created_before', created_before], |
28 | ['type', type], |
29 | ['include_data', include_data] |
30 | ]) { |
31 | if (v !== undefined && v !== '' && k !== undefined) { |
32 | url.searchParams.append(k, v) |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: 'GET', |
37 | headers: { |
38 | Authorization: `Basic ${token}` |
39 | }, |
40 | body: undefined |
41 | }) |
42 | if (!response.ok) { |
43 | const text = await response.text() |
44 | throw new Error(`${response.status} ${text}`) |
45 | } |
46 | return await response.text() |
47 | } |
48 |
|