1 | |
2 | |
3 | * Query discover events in table format |
4 | * Retrieves discover (also known as events) data for a given organization. |
5 | */ |
6 | export async function main( |
7 | auth: RT.Sentry, |
8 | field: string | undefined, |
9 | end?: string | undefined, |
10 | environment?: string | undefined, |
11 | project?: string | undefined, |
12 | start?: string | undefined, |
13 | statsPeriod?: string | undefined, |
14 | per_page?: string | undefined, |
15 | query?: string | undefined, |
16 | sort?: string | undefined |
17 | ) { |
18 | const url = new URL( |
19 | `https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/events/` |
20 | ) |
21 | for (const [k, v] of [ |
22 | ['field', field], |
23 | ['end', end], |
24 | ['environment', environment], |
25 | ['project', project], |
26 | ['start', start], |
27 | ['statsPeriod', statsPeriod], |
28 | ['per_page', per_page], |
29 | ['query', query], |
30 | ['sort', sort] |
31 | ]) { |
32 | if (v !== undefined && v !== '') { |
33 | url.searchParams.append(k, v) |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: 'GET', |
38 | headers: { |
39 | Authorization: 'Bearer ' + auth.token |
40 | }, |
41 | body: undefined |
42 | }) |
43 | if (!response.ok) { |
44 | const text = await response.text() |
45 | throw new Error(`${response.status} ${text}`) |
46 | } |
47 | return await response.json() |
48 | } |
49 |
|