0

List Templates

by
Published Nov 5, 2024

Optionally, filter by a search query or tags.

Script pandadoc Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Pandadoc = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Pandadoc,
8
	q: string | undefined,
9
	shared: string | undefined,
10
	deleted: string | undefined,
11
	count: string | undefined,
12
	page: string | undefined,
13
	id: string | undefined,
14
	folder_uuid: string | undefined,
15
	tag: string | undefined
16
) {
17
	const url = new URL(`https://api.pandadoc.com/public/v1/templates`)
18

19
	for (const [k, v] of [
20
		['q', q],
21
		['shared', shared],
22
		['deleted', deleted],
23
		['count', count],
24
		['page', page],
25
		['id', id],
26
		['folder_uuid', folder_uuid],
27
		['tag', tag]
28
	]) {
29
		if (v !== undefined && v !== '' && k !== undefined) {
30
			url.searchParams.append(k, v)
31
		}
32
	}
33

34
	const response = await fetch(url, {
35
		method: 'GET',
36
		headers: {
37
			Authorization: `API-Key ${auth.apiKey}`
38
		},
39
		body: undefined
40
	})
41

42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46

47
	return await response.json()
48
}
49