0

List API Log

by
Published Nov 5, 2024

Get the list of all logs within the selected workspace. Optionally filter by date, page, and `#` of items per page.

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
	since: string | undefined,
9
	to: string | undefined,
10
	count: string | undefined,
11
	page: string | undefined,
12
	statuses: string | undefined,
13
	methods: string | undefined,
14
	search: string | undefined,
15
	environment_type: 'PRODUCTION' | 'SANDBOX' | undefined
16
) {
17
	const url = new URL(`https://api.pandadoc.com/public/v1/logs`)
18

19
	for (const [k, v] of [
20
		['since', since],
21
		['to', to],
22
		['count', count],
23
		['page', page],
24
		['statuses', statuses],
25
		['methods', methods],
26
		['search', search],
27
		['environment_type', environment_type]
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