0

Check the status of a PDF

by
Published Dec 20, 2024
Script docspring Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Docspring = {
3
	tokenId: string
4
	tokenSecret: string
5
}
6
/**
7
 * Check the status of a PDF
8
 *
9
 */
10
export async function main(
11
	auth: Docspring,
12
	submission_id: string,
13
	include_data: string | undefined
14
) {
15
	const url = new URL(`https://api.docspring.com/api/v1/submissions/${submission_id}`)
16

17
	const token = btoa(auth.tokenId + ':' + auth.tokenSecret)
18

19
	for (const [k, v] of [['include_data', include_data]]) {
20
		if (v !== undefined && v !== '' && k !== undefined) {
21
			url.searchParams.append(k, v)
22
		}
23
	}
24
	const response = await fetch(url, {
25
		method: 'GET',
26
		headers: {
27
			Authorization: `Basic ${token}`
28
		},
29
		body: undefined
30
	})
31
	if (!response.ok) {
32
		const text = await response.text()
33
		throw new Error(`${response.status} ${text}`)
34
	}
35
	return await response.text()
36
}
37