1
//native
2
type Docspring = {
3
tokenId: string
4
tokenSecret: string
5
}
6
/**
7
* Get a list of all folders
8
*
9
*/
10
export async function main(auth: Docspring, parent_folder_id: string | undefined) {
11
const url = new URL(`https://api.docspring.com/api/v1/folders/`)
12
13
const token = btoa(auth.tokenId + ':' + auth.tokenSecret)
14
15
for (const [k, v] of [['parent_folder_id', parent_folder_id]]) {
16
if (v !== undefined && v !== '' && k !== undefined) {
17
url.searchParams.append(k, v)
18
19
20
const response = await fetch(url, {
21
method: 'GET',
22
headers: {
23
Authorization: `Basic ${token}`
24
},
25
body: undefined
26
})
27
if (!response.ok) {
28
const text = await response.text()
29
throw new Error(`${response.status} ${text}`)
30
31
return await response.text()
32
33