InfluxDB 1.x compatibility API

The InfluxDB v2 API includes InfluxDB 1.x compatibility endpoints that work with InfluxDB 1.x client libraries and third-party integrations like Grafana and others.

View full v1 compatibility API documentation

Authentication

InfluxDB 1.x compatibility endpoints require all query and write requests to be authenticated with an API token or 1.x-compatible credentials.

Authenticate with the Token scheme

Token authentication requires the following credential:

Use the Authorization header with the Token scheme to provide your token to InfluxDB.

Syntax

  1. Authorization: Token INFLUX_API_TOKEN

Example

curl Node.js

  1. #######################################
  2. # Use a token in the Authorization header
  3. # to query the InfluxDB 1.x compatibility API.
  4. #
  5. # Replace INFLUX_API_TOKEN with your InfluxDB API token.
  6. #######################################
  7. curl --get "http://localhost:8086" \
  8. --header "Authorization: Token INFLUX_API_TOKEN" \
  9. --header 'Content-type: application/json' \
  10. --data-urlencode "db=mydb" \
  11. --data-urlencode "q=SELECT * FROM cpu_usage"
  1. /**
  2. * Use the Token authentication scheme
  3. * to query the InfluxDB 1.x compatibility API.
  4. *
  5. * Replace INFLUX_API_TOKEN with your InfluxDB API token.
  6. */
  7. const https = require('https');
  8. const querystring = require('querystring');
  9. function queryWithToken() {
  10. const queryparams = {
  11. db: 'mydb',
  12. q: 'SELECT * FROM cpu_usage',
  13. };
  14. const options = {
  15. host: 'localhost:8086',
  16. path: "/query?" + querystring.stringify(queryparams),
  17. headers: {
  18. 'Authorization': 'Token INFLUX_API_TOKEN',
  19. 'Content-type': 'application/json'
  20. },
  21. };
  22. const request = https.get(options, (response) => {
  23. let rawData = '';
  24. response.on('data', () => {
  25. response.on('data', (chunk) => { rawData += chunk; });
  26. })
  27. response.on('end', () => {
  28. console.log(rawData);
  29. })
  30. });
  31. request.end();
  32. }

Authenticate with a username and password scheme

Use the following authentication schemes with clients that support the InfluxDB 1.x convention of username and password (that don’t support the Authorization: Token scheme):

Manage credentials

Username and password schemes require the following credentials:

  • username: 1.x username (this is separate from the UI login username)
  • password: 1.x password or InfluxDB API token.

Password or Token

If you have set a password for the 1.x-compatible username, provide the 1.x-compatible password. If you haven’t set a password for the 1.x-compatible username, provide the InfluxDB authentication token as the password.

For information about creating and managing 1.x-compatible authorizations, see:

Basic authentication

Use the Authorization header with the Basic scheme to provide username and password credentials to InfluxDB.

Most HTTP clients provide a Basic authentication option that accepts the <username>:<password> syntax and encodes the credentials before sending the request.

Syntax
  1. Authorization: Basic INFLUX_USERNAME:INFLUX_PASSWORD_OR_TOKEN
Example

curl Node.js

  1. #######################################
  2. # Use Basic authentication with an
  3. # InfluxDB 1.x compatible username and password
  4. # to query the InfluxDB 1.x compatibility API.
  5. #
  6. # Replace INFLUX_USERNAME with your 1.x-compatible username.
  7. # Replace INFLUX_PASSWORD_OR_TOKEN with your InfluxDB API token
  8. # or 1.x-compatible password.
  9. #######################################
  10. # Use the default retention policy.
  11. #######################################
  12. # Use the --user option with `--user <username>:<password>` syntax
  13. # or the `--user <username>` interactive syntax to ensure your credentials are
  14. # encoded in the header.
  15. #######################################
  16. curl get "http://localhost:8086/query"
  17. user "INFLUX_USERNAME":"INFLUX_PASSWORD_OR_TOKEN"
  18. data-urlencode "db=mydb"
  19. data-urlencode "q=SELECT * FROM cpu_usage"
  1. /**
  2. * Use Basic authentication with an
  3. * InfluxDB 1.x compatible username and password
  4. * to query the InfluxDB 1.x compatibility API.
  5. * Replace INFLUX_USERNAME with your 1.x-compatible username.
  6. * Replace INFLUX_PASSWORD_OR_TOKEN with your InfluxDB API token
  7. * or 1.x-compatible password.
  8. * Use the default retention policy.
  9. */
  10. const https = require('https');
  11. const querystring = require('querystring');
  12. function queryWithUsername() {
  13. const queryparams = {
  14. db: 'mydb',
  15. q: 'SELECT * FROM cpu_usage',
  16. };
  17. const options = {
  18. host: 'localhost:8086',
  19. path: '/query?' + querystring.stringify(queryparams),
  20. auth: 'INFLUX_USERNAME:INFLUX_PASSWORD_OR_TOKEN',
  21. headers: {
  22. 'Content-type': 'application/json'
  23. },
  24. };
  25. const request = https.get(options, (response) => {
  26. let rawData = '';
  27. response.on('data', () => {
  28. response.on('data', (chunk) => { rawData += chunk; });
  29. })
  30. response.on('end', () => {
  31. console.log(rawData);
  32. })
  33. });
  34. request.end();
  35. }

Query string authentication

Use InfluxDB 1.x API parameters to provide credentials through the query string.

Consider when using query string parameters
  • URL-encode query parameters that may contain whitespace or other special characters.
  • Be aware of the risks when exposing sensitive data through URLs.
Syntax
  1. /query/?u=INFLUX_USERNAME&p=INFLUX_PASSWORD_OR_TOKEN
  2. /write/?u=INFLUX_USERNAME&p=INFLUX_PASSWORD_OR_TOKEN
Example

curl Node.js

  1. #######################################
  2. # Use querystring authentication with an
  3. # InfluxDB 1.x compatible username and password
  4. # to query the InfluxDB 1.x compatibility API.
  5. #
  6. # Replace INFLUX_USERNAME with your 1.x-compatible username.
  7. # Replace INFLUX_PASSWORD_OR_TOKEN with your InfluxDB API token
  8. # or 1.x-compatible password.
  9. #
  10. # Use the default retention policy.
  11. #######################################
  12. curl get "http://localhost:8086/query"
  13. data-urlencode "u=INFLUX_USERNAME"
  14. data-urlencode "p=INFLUX_PASSWORD_OR_TOKEN"
  15. data-urlencode "db=mydb"
  16. data-urlencode "q=SELECT * FROM cpu_usage"
  1. /**
  2. * Use querystring authentication with an
  3. * InfluxDB 1.x compatible username and password
  4. * to query the InfluxDB 1.x compatibility API.
  5. *
  6. * Replace INFLUX_USERNAME with your 1.x-compatible username.
  7. * Replace INFLUX_PASSWORD_OR_TOKEN with your InfluxDB API token
  8. * or 1.x-compatible password.
  9. *
  10. * Use the default retention policy.
  11. */
  12. const https = require('https');
  13. const querystring = require('querystring');
  14. function queryWithToken() {
  15. const queryparams = {
  16. db: 'mydb',
  17. q: 'SELECT * FROM cpu_usage',
  18. u: 'INFLUX_USERNAME',
  19. p: 'INFLUX_PASSWORD_OR_TOKEN'
  20. };
  21. const options = {
  22. host: 'localhost:8086',
  23. path: "/query?" + querystring.stringify(queryparams)
  24. };
  25. const request = https.get(options, (response) => {
  26. let rawData = '';
  27. response.on('data', () => {
  28. response.on('data', (chunk) => { rawData += chunk; });
  29. })
  30. response.on('end', () => {
  31. console.log(rawData);
  32. })
  33. });
  34. request.end();
  35. }

Replace the following:

InfluxQL support

The compatibility API supports InfluxQL, with the following caveats:

  • The INTO clause (e.g. SELECT ... INTO ...) is not supported.
  • With the exception of DELETE and DROP MEASUREMENT queries, which are still allowed, InfluxQL database management commands are not supported.

Compatibility endpoints

/query

The /query 1.x compatibility endpoint queries InfluxDB Cloud and InfluxDB OSS 2.x using InfluxQL.

  1. GET http://localhost:8086/query

Read more

/write

The /write 1.x compatibility endpoint writes data to InfluxDB Cloud and InfluxDB OSS 2.x using patterns from the InfluxDB 1.x /write API endpoint.

  1. POST http://localhost:8086/write

Read more

Database and retention policy mapping

The database and retention policy (DBRP) mapping service maps InfluxDB 1.x database and retention policy combinations to InfluxDB Cloud and InfluxDB OSS 2.x buckets.

influxql query write