0

Get Saved Searches

by
Published Oct 17, 2025

List all the saved searches for the current user

Script their_stack Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type TheirStack = {
3
	apiKey: string
4
}
5
/**
6
 * Get Saved Searches
7
 * List all the saved searches for the current user
8
 */
9
export async function main(
10
	auth: TheirStack,
11
	user_ids: string | undefined,
12
	types: string | undefined,
13
	order_by: 'name' | 'created_at' | 'updated_at' | undefined,
14
	order_direction: 'asc' | 'desc' | undefined
15
) {
16
	const url = new URL(`https://api.theirstack.com/v0/saved_searches`)
17
	for (const [k, v] of [
18
		['user_ids', user_ids],
19
		['types', types],
20
		['order_by', order_by],
21
		['order_direction', order_direction]
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: 'Bearer ' + auth.apiKey
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.json()
39
}
40