//native
type Docspring = {
tokenId: string
tokenSecret: string
}
/**
* List all submissions for a given template
*
*/
export async function main(
auth: Docspring,
template_id: string,
cursor: string | undefined,
limit: string | undefined,
created_after: string | undefined,
created_before: string | undefined,
type: string | undefined,
include_data: string | undefined
) {
const url = new URL(`https://api.docspring.com/api/v1/templates/${template_id}/submissions`)
const token = btoa(auth.tokenId + ':' + auth.tokenSecret)
for (const [k, v] of [
['cursor', cursor],
['limit', limit],
['created_after', created_after],
['created_before', created_before],
['type', type],
['include_data', include_data]
]) {
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