Explore logs Query API

Run Explore logs queries with an HTTP API.

Follow redirects

Make sure to follow redirects when using this API.
For example, use the -L option with curl.

GET https://logs.betterstack.com/api/v2/query/explore-logs

Query parameters

source_ids
required string
query
required string
from
string
to
string

Headers

Authorization
required string
200

Response body

{"time":"2024-07-01 05:50:00","message":"Hello, world!"}
{"time":"2024-06-30 00:00:00","message":"Hello, you!"}
{"time":"2024-06-30 00:00:00","message":"Hello, me!"}

Example cURL

Example
curl -L --request GET \
  --header "Authorization: Bearer $TOKEN" \
  --data-urlencode "source_ids=$SOURCE_ID" \
  --data-urlencode "query=SELECT {{time}} as time, JSONExtract(json, 'level', 'Nullable(String)') AS level FROM {{source}} WHERE time BETWEEN {{start_time}} AND {{end_time}}" \
  https://logs.betterstack.com/api/v2/query/explore-logs

Adjusting the response format

By default rows are returned in the ClickHouse JSONEachRow format, you can change this by adding a FORMAT clause to you query.

See the ClickHouse documentation for more information.