docs-v2/content/influxdb/v2/api-guide/influxdb-1x/query.md

5.9 KiB

title list_title description menu weight influxdb/v2/tags list_code_example related aliases
/query 1.x compatibility API /query The `/query` 1.x compatibility endpoint queries InfluxDB Cloud and InfluxDB OSS 2.x using **InfluxQL**.
influxdb_v2
name parent
/query v1 compatibility
301
influxql
query
<pre> <span class="api get">GET</span> http://localhost:8086/query </pre>
/influxdb/v2/query-data/influxql
/influxdb/v2/reference/api/influxdb-1x/query/

The /query 1.x compatibility endpoint queries InfluxDB {{< current-version >}} using InfluxQL. Use the GET request method to query data from the /query endpoint.

GET http://localhost:8086/query

The /query compatibility endpoint uses the database and retention policy specified in the query request to map the request to an InfluxDB bucket. For more information, see Database and retention policy mapping.

{{% show-in "cloud,cloud-serverless" %}}

{{% note %}} If you have an existing bucket that doesn't follow the database/retention-policy naming convention, you must manually create a database and retention policy mapping to query that bucket with the /query compatibility API. {{% /note %}}

{{% /show-in %}}

Authentication

Use one of the following authentication methods:

  • token authentication
  • basic authentication with username and password
  • query string authentication with username and password

For more information, see Authentication.

Query string parameters

u

(Optional) The 1.x username to authenticate the request. See query string authentication.

p

(Optional) The 1.x password to authenticate the request. See query string authentication.

db

({{< req >}}) The database to query data from. This is mapped to an InfluxDB bucket. See Database and retention policy mapping.

rp

The retention policy to query data from. This is mapped to an InfluxDB bucket. See Database and retention policy mapping.

q

({{< req >}}) The InfluxQL query to execute. To execute multiple queries, delimit queries with a semicolon (;).

epoch

Return results with Unix timestamps (also known as epoch timestamps) in the specified precision instead of RFC3339 timestamps with nanosecond precision. The following precisions are available:

  • ns - nanoseconds
  • u or µ - microseconds
  • ms - milliseconds
  • s - seconds
  • m - minutes
  • h - hours

Query examples

{{% code-placeholders "API_TOKEN" %}}

Query using basic authentication

{{% show-in "v2" %}}

{{< code-tabs-wrapper >}} {{% code-tabs %}} curl Node.js {{% /code-tabs %}} {{% code-tab-content %}}

{{% get-shared-text "api/v1-compat/auth/oss/basic-auth.sh" %}}

{{% /code-tab-content %}} {{% code-tab-content %}}

{{% get-shared-text "api/v1-compat/auth/oss/basic-auth.js" %}}

{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}

{{% /show-in %}}

{{% show-in "cloud,cloud-serverless" %}}

{{< code-tabs-wrapper >}} {{% code-tabs %}} curl Node.js {{% /code-tabs %}} {{% code-tab-content %}}

{{% get-shared-text "api/v1-compat/auth/cloud/basic-auth.sh" %}}

{{% /code-tab-content %}} {{% code-tab-content %}}

{{% get-shared-text "api/v1-compat/auth/cloud/basic-auth.js" %}}

{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}

{{% /show-in %}}

Query a non-default retention policy
curl --get http://localhost:8086/query \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "db=mydb" \
  --data-urlencode "rp=customrp" \
  --data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
Execute multiple queries
curl --get http://localhost:8086/query \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "db=mydb" \
  --data-urlencode "q=SELECT * FROM mem WHERE host=host1;SELECT mean(used_percent) FROM mem WHERE host=host1 GROUP BY time(10m)"
Return query results with millisecond Unix timestamps
curl --get http://localhost:8086/query \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "db=mydb" \
  --data-urlencode "rp=myrp" \
  --data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1" \
  --data-urlencode "epoch=ms"
Execute InfluxQL queries from a file
curl --get http://localhost:8086/query \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "db=mydb" \
  --data-urlencode "q@path/to/influxql.txt" \
  --data-urlencode "async=true"

{{% /code-placeholders %}}

Replace the following:

  • {{% code-placeholder-key %}}API_TOKEN{{% /code-placeholder-key %}}: your InfluxDB API token