0
Get saved filters
One script reply has been approved by the moderators Verified

List all the project's saved filters (each filter's name, ID and filter value)

Created by hugo697 2 days ago Viewed 0 times
0
Submitted by hugo697 Bun
Verified 2 days ago
1
//native
2
type Botify = {
3
	token: string
4
}
5
/**
6
 * Get saved filters
7
 * List all the project's saved filters (each filter's name, ID and filter value)
8
 */
9
export async function main(
10
	auth: Botify,
11
	username: string,
12
	project_slug: string,
13
	page: string | undefined,
14
	size: string | undefined,
15
	search: string | undefined
16
) {
17
	const url = new URL(`https://api.botify.com/projects/${username}/${project_slug}/filters`)
18
	for (const [k, v] of [
19
		['page', page],
20
		['size', size],
21
		['search', search]
22
	]) {
23
		if (v !== undefined && v !== '' && k !== undefined) {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27
	const response = await fetch(url, {
28
		method: 'GET',
29
		headers: {
30
			Authorization: 'Token ' + auth.token
31
		},
32
		body: undefined
33
	})
34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38
	return await response.text()
39
}
40