0

List Templates Folders

by
Published Nov 5, 2024

Get the list of folders that contain Templates in your account.

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
	parent_uuid: string | undefined,
9
	count: string | undefined,
10
	page: string | undefined
11
) {
12
	const url = new URL(`https://api.pandadoc.com/public/v1/templates/folders`)
13

14
	for (const [k, v] of [
15
		['parent_uuid', parent_uuid],
16
		['count', count],
17
		['page', page]
18
	]) {
19
		if (v !== undefined && v !== '' && k !== undefined) {
20
			url.searchParams.append(k, v)
21
		}
22
	}
23

24
	const response = await fetch(url, {
25
		method: 'GET',
26
		headers: {
27
			Authorization: `API-Key ${auth.apiKey}`
28
		},
29
		body: undefined
30
	})
31

32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36

37
	return await response.json()
38
}
39