0

List an organizations discover saved queries

by
Published Oct 17, 2025

Retrieve a list of saved queries that are associated with the given organization.

Script sentry Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * List an organizations discover saved queries
4
 * Retrieve a list of saved queries that are associated with the given organization.
5
 */
6
export async function main(
7
	auth: RT.Sentry,
8
	per_page?: string | undefined,
9
	cursor?: string | undefined,
10
	query?: string | undefined,
11
	sortBy?: string | undefined
12
) {
13
	const url = new URL(
14
		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/discover/saved/`
15
	)
16
	for (const [k, v] of [
17
		['per_page', per_page],
18
		['cursor', cursor],
19
		['query', query],
20
		['sortBy', sortBy]
21
	]) {
22
		if (v !== undefined && v !== '') {
23
			url.searchParams.append(k, v)
24
		}
25
	}
26
	const response = await fetch(url, {
27
		method: 'GET',
28
		headers: {
29
			Authorization: 'Bearer ' + auth.token
30
		},
31
		body: undefined
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.json()
38
}
39