0

Retrieve release health session statistics

by
Published Oct 17, 2025

Returns a time series of release health session statistics for projects bound to an organization.

Script sentry Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Retrieve release health session statistics
4
 * Returns a time series of release health session statistics for projects bound to an organization.
5
 */
6
export async function main(
7
	auth: RT.Sentry,
8
	field: string | undefined,
9
	start?: string | undefined,
10
	end?: string | undefined,
11
	environment?: string | undefined,
12
	statsPeriod?: string | undefined,
13
	project?: string | undefined,
14
	per_page?: string | undefined,
15
	interval?: string | undefined,
16
	groupBy?: string | undefined,
17
	orderBy?: string | undefined,
18
	includeTotals?: string | undefined,
19
	includeSeries?: string | undefined,
20
	query?: string | undefined
21
) {
22
	const url = new URL(
23
		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/sessions/`
24
	)
25
	for (const [k, v] of [
26
		['field', field],
27
		['start', start],
28
		['end', end],
29
		['environment', environment],
30
		['statsPeriod', statsPeriod],
31
		['project', project],
32
		['per_page', per_page],
33
		['interval', interval],
34
		['groupBy', groupBy],
35
		['orderBy', orderBy],
36
		['includeTotals', includeTotals],
37
		['includeSeries', includeSeries],
38
		['query', query]
39
	]) {
40
		if (v !== undefined && v !== '') {
41
			url.searchParams.append(k, v)
42
		}
43
	}
44
	const response = await fetch(url, {
45
		method: 'GET',
46
		headers: {
47
			Authorization: 'Bearer ' + auth.token
48
		},
49
		body: undefined
50
	})
51
	if (!response.ok) {
52
		const text = await response.text()
53
		throw new Error(`${response.status} ${text}`)
54
	}
55
	return await response.json()
56
}
57