//native
type Docspring = {
tokenId: string
tokenSecret: string
}
/**
* Get a list of all folders
*
*/
export async function main(auth: Docspring, parent_folder_id: string | undefined) {
const url = new URL(`https://api.docspring.com/api/v1/folders/`)
const token = btoa(auth.tokenId + ':' + auth.tokenSecret)
for (const [k, v] of [['parent_folder_id', parent_folder_id]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Basic ${token}`
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.text()
}
Submitted by hugo697 536 days ago