# Legacy Query API v1

[warning]
#### This API endpoint is deprecated
This API endpoint will be fully decommissioned on Thursday, 15th August 2024 at 16:00 UTC.
Please migrate to [Query API v2 - Live Tail](https://betterstack.com/docs/logs/query-api/v2/live-tail/).
[/warning]

Fetch your Live Tail logs with a HTTP API.

Querying Live Tail returns rows based on your query. Each request returns a `pagination.next` url which you can query for more logs. Note that the URL contains a `cursor` query that works only when you don't change any query parameters, otherwise the behavior is not defined.

[endpoint]
base_url = "https://telemetry.betterstack.com"
path = "/api/v1/query"
method = "GET"

[[query_param]]
name = "source_ids"
description = "Comma-separated list of sources you want to query."
required = false
type = "string"

[[query_param]]
name = "query"
description = "Filter logs with your query. This follows the same rules as Live tail. Read more about [Live tail Query Language](https://betterstack.com/docs/logs/using-logtail/live-tail-query-language/)."
required = false
type = "string"

[[query_param]]
name = "batch"
description = "How many rows do you want to return? Accepts a range of 50-1000.\n Default: 100 rows."
required = false
type = "integer"

[[query_param]]
name = "from"
description = "Start of time range for the log query (ISO8601-formatted string: 2022-07-19T13:32:56+0000). Default: 30 minutes before `to`. If `to` is not specified then 30 minutes ago."
required = false
type = "string"

[[query_param]]
name = "to"
description = "End of time range for the log query (ISO8601-formatted string: 2022-07-19T13:32:56+0000).   Default: 30 minutes after `from`. If `from` is not specified then current time."
required = false
type = "string"

[[query_param]]
name = "order"
description = "In what order do you want your logs? Possible values: `newest_first`, `oldest_first`. Default: `newest_first`"
required = false
type = "string"

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 200
description = '''Returned rows'''
body = '''{
  "data": [
    {
      "app": "sample_app",
      "source_id": "123",
      "dt": "2022-07-19 12:28:14.000000",
      "event.http_request_received.port": null,
      "event.http_response_sent.status": null,
      "message": "Hello, world!",
      "level": "debug",
      "context.runtime.thread_id": "70039367973540",
      "context.system.pid": "14",
      "context.http.path": null,
      "context.http.method": null,
      "context.http.host": null,
      "context.http.remote_addr": null
    },
    {
      "app": "sample_app",
      "source_id": "123",
      "dt": "2022-07-19 12:28:14.000000",
      "event.http_request_received.port": null,
      "event.http_response_sent.status": null,
      "message": "Hello, world!",
      "level": "debug",
      "context.runtime.thread_id": "70182641597580",
      "context.system.pid": "14",
      "context.http.path": null,
      "context.http.method": null,
      "context.http.host": null,
      "context.http.remote_addr": null
    }
  ],
  "pagination": {
    "next": "https://telemetry.betterstack.com/api/v1/query?batch=100&cursor=MjE5PTI%3D&from=2022-07-18+12%3A29%3A14+UTC&order=newest_first&source_ids=123&to=2022-07-19+12%3A28%3A14+UTC"
  }
}'''
[/responses]

#### Example cURL 

```shell
[label Example]
curl --request GET \
  --url https://telemetry.betterstack.com/api/v1/query \
  --header "Authorization: Bearer $TOKEN"
```

[info]
#### Looking for details of a specific parameter?
Explore [list of all Sources API response parameters](https://betterstack.com/docs/logs/api/sources-api-response-parameters/)
[/info]