0

Retrieve a monitor

by
Published Oct 17, 2025

Retrieves details for a monitor.

Script sentry Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Retrieve a monitor
4
 * Retrieves details for a monitor.
5
 */
6
export async function main(
7
	auth: RT.Sentry,
8
	monitor_id_or_slug: string,
9
	environment?: string | undefined
10
) {
11
	const url = new URL(
12
		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/monitors/${monitor_id_or_slug}/`
13
	)
14
	for (const [k, v] of [['environment', environment]]) {
15
		if (v !== undefined && v !== '') {
16
			url.searchParams.append(k, v)
17
		}
18
	}
19
	const response = await fetch(url, {
20
		method: 'GET',
21
		headers: {
22
			Authorization: 'Bearer ' + auth.token
23
		},
24
		body: undefined
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.json()
31
}
32