0

List Content Library Item

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
	id: string | undefined,
10
	deleted: string | undefined,
11
	folder_uuid: string | undefined,
12
	count: string | undefined,
13
	page: string | undefined,
14
	tag: string | undefined
15
) {
16
	const url = new URL(`https://api.pandadoc.com/public/v1/content-library-items`)
17

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

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

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

45
	return await response.json()
46
}
47