//native
/**
* Create a new saved query
* Create a new saved query for the given organization.
*/
export async function main(auth: RT.Sentry, body: Body) {
const url = new URL(
`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/discover/saved/`
)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
export interface Body {
/**
* The user-defined saved query name.
*/
name: string
/**
* The saved projects filter for this query.
*/
projects?: number[]
/**
* The dataset you would like to query. Note: `discover` is a **deprecated** value. The allowed values are: `error-events`, `transaction-like`
*
* * `discover`
* * `error-events`
* * `transaction-like`
*/
queryDataset?: 'discover' | 'error-events' | 'transaction-like'
/**
* The saved start time for this saved query.
*/
start?: string
/**
* The saved end time for this saved query.
*/
end?: string
/**
* The saved time range period for this saved query.
*/
range?: string
/**
* The fields, functions, or equations that can be requested for the query. At most 20 fields can be selected per request. Each field can be one of the following types:
* - A built-in key field. See possible fields in the [properties table](/product/sentry-basics/search/searchable-properties/#properties-table), under any field that is an event property.
* - example: `field=transaction`
* - A tag. Tags should use the `tag[]` formatting to avoid ambiguity with any fields
* - example: `field=tag[isEnterprise]`
* - A function which will be in the format of `function_name(parameters,...)`. See possible functions in the [query builder documentation](/product/discover-queries/query-builder/#stacking-functions).
* - when a function is included, Discover will group by any tags or fields
* - example: `field=count_if(transaction.duration,greater,300)`
* - An equation when prefixed with `equation|`. Read more about [equations here](/product/discover-queries/query-builder/query-equations/).
* - example: `field=equation|count_if(transaction.duration,greater,300) / count() * 100`
*
*/
fields?: string[]
/**
* How to order the query results. Must be something in the `field` list, excluding equations.
*/
orderby?: string
/**
* The name of environments to filter by.
*/
environment?: string[]
/**
* Filters results by using [query syntax](/product/sentry-basics/search/).
*/
query?: string
/**
* Aggregate functions to be plotted on the chart.
*/
yAxis?: string[]
/**
* Visualization type for saved query chart. Allowed values are:
* - default
* - previous
* - top5
* - daily
* - dailytop5
* - bar
*
*/
display?: string
/**
* Number of top events' timeseries to be visualized.
*/
topEvents?: number
/**
* Resolution of the time series.
*/
interval?: string
[k: string]: unknown
}
Submitted by hugo697 235 days ago