0

Caution This endpoint may change in the future without notice.

by
Published Oct 17, 2025

Return a set of points representing a normalized timestamp and the number of events seen in the period. Query ranges are limited to Sentry's configured time-series resolutions.

Script sentry Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Caution
4
This endpoint may change in the future without  notice.
5
 * Return a set of points representing a normalized timestamp and the
6
number of events seen in the period.
7

8
Query ranges are limited to Sentry's configured time-series resolutions.
9
 */
10
export async function main(
11
	auth: RT.Sentry,
12
	project_id_or_slug: string,
13
	stat?: 'received' | 'rejected' | 'blacklisted' | 'generated' | undefined,
14
	since?: string | undefined,
15
	until?: string | undefined,
16
	resolution?: '10s' | '1h' | '1d' | undefined
17
) {
18
	const url = new URL(
19
		`https://${auth.region}.sentry.io/api/0/projects/${auth.organizationSlug}/${project_id_or_slug}/stats/`
20
	)
21
	for (const [k, v] of [
22
		['stat', stat],
23
		['since', since],
24
		['until', until],
25
		['resolution', resolution]
26
	]) {
27
		if (v !== undefined && v !== '') {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			Authorization: 'Bearer ' + auth.token
35
		},
36
		body: undefined
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44