#
Queries API
The queries API is used to create and manage queries.
#
Create Query
#
Request
The payload to create a query should follow the specs below. All fields are optional:
namespaces
: a list of namespaces to run the query againstkeys
: a list of objects representing the fields to retrieve, Eachkey
consists of akey
(the name of the key to retrieve) and itstype
.calculations
: a list of calculations to perform on the events. Calculations consist of akey
andoperator
. If theoperator
isCOUNT
, a key is not necessary.calculations
andkeys
cannot be used simultaneously.filters
: a list of objects representing the filters to apply to the query. Each filter consists of akey
, anoperation
and avalue
. The value could be:- a literal value
- another
key
/type
pair; the key can be a materialized key
filter_combination
:AND
orOR
. If the list of filters contains multiple filters,filter_combination
defines how they are applied.AND
: find events matching all filtersOR
: find events matching any filter
group_bys
: a list ofkey
/type
pairs to group your result by.orders
: a list of objects describing how to order the query results. Each item should include akey
, atype
and aorder
which takes eitherASCENDING
orDESCENDING
name
: the name of the querydescription
: a description of the query
Sample request:
terminal
curl https://go.baselime.io/v1/queries -X POST \
-H "Authorization: YOUR_API_KEY" \
-d '
{
"namespaces": [
{
"type": "lambda",
"value": "prod-user-login"
}
],
"calculations": [{ "operator": "MAX" , "key": "@billedDuration"}],
"filters": [
{"key": "@duration", "operation": ">", "value": "200"},
{"key": "@sampled", "operation": "=", "value": true}
],
"filter_combination": "OR",
"group_bys": [{ "key": "@initDuration", "type": "number"}],
"orders": [{ "key": "@initDuration", "type": "number", "order": "DESCENDING"}],
"name": "Sample query",
"description": "A sample description"
}
'
#
Sample Response
output
{
"query": {
"id": "abcdefgh"
}
}
#
Get Query
#
Request
To retrieve a query, send a GET
request to /v1/queries/<query_id>
.
terminal
curl https://go.baselime.io/v1/queries/<query_id> -X GET \
-H "Authorization: YOUR_API_KEY"
#
Sample Response
output
{
"query": {
"id": "abcdefgh",
"namespaces": [
{
"type": "lambda",
"value": "prod-user-login"
}
],
"calculations": [{ "operator": "MAX" , "key": "@billedDuration"}],
"filters": [
{"key": "@duration", "operation": ">", "value": "200"},
{"key": "@sampled", "operation": "=", "value": true}
],
"filter_combination": "OR",
"group_bys": [{ "key": "@initDuration", "type": "number"}],
"orders": [{ "key": "@initDuration", "type": "number", "order": "DESCENDING"}],
"name": "Sample query",
"description": "A sample description",
"created_at": "2021-12-25T04:24:38Z",
"updated_at": "2021-12-25T04:24:38Z",
"author": "d98f27fc-f472-4338-ac3e-55d3089ff6fb"
}
}
#
Update Query
#
Request
To update a query, send a PUT
request to /v1/queries/<query_id>
. The request body should include all fields that you wish to edit on the query. Only included fields will be updated.
terminal
curl https://go.baselime.io/v1/queries/<query_id> -X PUT \
-H "Authorization: YOUR_API_KEY" \
-d '
{
"namespaces": [
{
"type": "lambda",
"value": "prod-user-login"
},
{
"type": "lambda",
"value": "prod-user-signup"
}
],
"filter_combination": "AND",
"name": "Updated sample query",
}
'
#
Sample Response
output
{
"query": {
"id": "abcdefgh",
"namespaces": [
{
"type": "lambda",
"value": "prod-user-login"
},
{
"type": "lambda",
"value": "prod-user-signup"
}
],
"calculations": [{ "operator": "MAX" , "key": "@billedDuration"}],
"filters": [
{"key": "@duration", "operation": ">", "value": "200"},
{"key": "@sampled", "operation": "=", "value": true}
],
"filter_combination": "AND",
"group_bys": [{ "key": "@initDuration", "type": "number"}],
"orders": [{ "key": "@initDuration", "type": "number", "order": "DESCENDING"}],
"name": "Updated sample query",
"description": "A sample description",
"created_at": "2021-12-25T04:24:38Z",
"updated_at": "2021-12-25T04:24:38Z",
"author": "d98f27fc-f472-4338-ac3e-55d3089ff6fb"
}
}
#
Delete Query
#
Request
To delete a query, send a DELETE
request to /v1/queries/<query_id>
. If other resources such as alerts use the current query, the delete operation will fail and respond with status code 403
.
terminal
curl https://go.baselime.io/v1/queries/<query_id> -X DELETE \
-H "Authorization: YOUR_API_KEY"
#
Sample Response
output
{
"query": {
"id": "abcdefgh"
}
}
#
List Queries
#
Request
To list queries, send a GET
request to /v1/queries/
.
terminal
curl https://go.baselime.io/v1/queries -X GET \
-H "Authorization: YOUR_API_KEY"
#
Sample Response
output
{
"queries": [
{
"id": "abcdefgh",
"namespaces": [
{
"type": "lambda",
"value": "prod-user-login"
},
{
"type": "lambda",
"value": "prod-user-signup"
}
],
"calculations": [{ "operator": "MAX" , "key": "@billedDuration"}],
"filters": [
{"key": "@duration", "operation": ">", "value": "200"},
{"key": "@sampled", "operation": "=", "value": true}
],
"filter_combination": "AND",
"group_bys": [{ "key": "@initDuration", "type": "number"}],
"orders": [{ "key": "@initDuration", "type": "number", "order": "DESCENDING"}],
"name": "Updated sample query",
"description": "A sample description",
"created_at": "2021-12-25T04:24:38Z",
"updated_at": "2021-12-25T04:24:38Z",
"author": "d98f27fc-f472-4338-ac3e-55d3089ff6fb"
},
... more queries ...
]
}