0

List webhooks

by
Published Oct 17, 2025

List webhooks that you are subscribed to.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * List webhooks
7
 * List webhooks that you are subscribed to.
8
 */
9
export async function main(
10
	auth: Codat,
11
	page: string | undefined,
12
	pageSize: string | undefined,
13
	query: string | undefined,
14
	orderBy: string | undefined
15
) {
16
	const url = new URL(`https://api.codat.io/rules`)
17
	for (const [k, v] of [
18
		['page', page],
19
		['pageSize', pageSize],
20
		['query', query],
21
		['orderBy', orderBy]
22
	]) {
23
		if (v !== undefined && v !== '' && k !== undefined) {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27

28
	const response = await fetch(url, {
29
		method: 'GET',
30
		headers: {
31
			Authorization: `Basic ${auth.encodedKey}`
32
		},
33
		body: undefined
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41