0

Get webhook event page

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
	count: string | undefined,
9
	page: string | undefined,
10
	since: string | undefined,
11
	to: string | undefined,
12
	type: string | undefined,
13
	http_status_code: string | undefined,
14
	error: string | undefined
15
) {
16
	const url = new URL(`https://api.pandadoc.com/public/v1/webhook-events`)
17

18
	for (const [k, v] of [
19
		['count', count],
20
		['page', page],
21
		['since', since],
22
		['to', to],
23
		['type', type],
24
		['http_status_code', http_status_code],
25
		['error', error]
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