0

List documents

by
Published Nov 5, 2024
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
	completed_from: string | undefined,
9
	completed_to: string | undefined,
10
	contact_id: string | undefined,
11
	count: string | undefined,
12
	created_from: string | undefined,
13
	created_to: string | undefined,
14
	deleted: string | undefined,
15
	id: string | undefined,
16
	folder_uuid: string | undefined,
17
	form_id: string | undefined,
18
	membership_id: string | undefined,
19
	metadata: string | undefined,
20
	modified_from: string | undefined,
21
	modified_to: string | undefined,
22
	order_by:
23
		| 'name'
24
		| 'date_created'
25
		| 'date_status_changed'
26
		| 'date_of_last_action'
27
		| 'date_modified'
28
		| 'date_sent'
29
		| 'date_completed'
30
		| 'date_expiration'
31
		| 'date_declined'
32
		| 'status'
33
		| '-name'
34
		| '-date_created'
35
		| '-date_status_changed'
36
		| '-date_of_last_action'
37
		| '-date_modified'
38
		| '-date_sent'
39
		| '-date_completed'
40
		| '-date_expiration'
41
		| '-date_declined'
42
		| '-status'
43
		| undefined,
44
	page: string | undefined,
45
	q: string | undefined,
46
	status:
47
		| '0'
48
		| '1'
49
		| '2'
50
		| '3'
51
		| '4'
52
		| '5'
53
		| '6'
54
		| '7'
55
		| '8'
56
		| '9'
57
		| '10'
58
		| '11'
59
		| '12'
60
		| '13'
61
		| undefined,
62
	status__ne:
63
		| '0'
64
		| '1'
65
		| '2'
66
		| '3'
67
		| '4'
68
		| '5'
69
		| '6'
70
		| '7'
71
		| '8'
72
		| '9'
73
		| '10'
74
		| '11'
75
		| '12'
76
		| '13'
77
		| undefined,
78
	tag: string | undefined,
79
	template_id: string | undefined
80
) {
81
	const url = new URL(`https://api.pandadoc.com/public/v1/documents`)
82

83
	for (const [k, v] of [
84
		['completed_from', completed_from],
85
		['completed_to', completed_to],
86
		['contact_id', contact_id],
87
		['count', count],
88
		['created_from', created_from],
89
		['created_to', created_to],
90
		['deleted', deleted],
91
		['id', id],
92
		['folder_uuid', folder_uuid],
93
		['form_id', form_id],
94
		['membership_id', membership_id],
95
		['metadata', metadata],
96
		['modified_from', modified_from],
97
		['modified_to', modified_to],
98
		['order_by', order_by],
99
		['page', page],
100
		['q', q],
101
		['status', status],
102
		['status__ne', status__ne],
103
		['tag', tag],
104
		['template_id', template_id]
105
	]) {
106
		if (v !== undefined && v !== '' && k !== undefined) {
107
			url.searchParams.append(k, v)
108
		}
109
	}
110

111
	const response = await fetch(url, {
112
		method: 'GET',
113
		headers: {
114
			Authorization: `API-Key ${auth.apiKey}`
115
		},
116
		body: undefined
117
	})
118

119
	if (!response.ok) {
120
		const text = await response.text()
121
		throw new Error(`${response.status} ${text}`)
122
	}
123

124
	return await response.json()
125
}
126