API Quick Start

InfluxDB offers a rich API and client libraries ready to integrate with your application. Use popular tools like Curl and Postman for rapidly testing API requests.

This section will guide you through the most commonly used API methods.

For detailed documentation on the entire API, see InfluxDBv2 API Reference.

If you need to use InfluxDB 2.2 with InfluxDB 1.x API clients and integrations, see the 1.x compatibility API.

Bootstrap your application

With most API requests, you’ll need to provide a minimum of your InfluxDB URL, Organization, and Authorization Token.

Install InfluxDB OSS v2.x or upgrade to an InfluxDB Cloud account.

Authentication

InfluxDB uses API tokens to authorize API requests.

  1. Before exploring the API, use the InfluxDB UI to create an initial API token for your application.

  2. Include your API token in an Authentication: Token YOUR_API_TOKEN HTTP header with each request.

curl Node.js

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

Postman is another popular tool for exploring APIs. See how to send authenticated requests with Postman.

Buckets API

Before writing data you’ll need to create a Bucket in InfluxDB. Create a bucket using an HTTP request to the InfluxDB API /buckets endpoint.

  1. INFLUX_TOKEN=YOUR_API_TOKEN
  2. INFLUX_ORG_ID=YOUR_ORG_ID
  3. curl --request POST \
  4. "http://localhost:8086/api/v2/buckets" \
  5. --header "Authorization: Token ${INFLUX_TOKEN}" \
  6. --header "Content-type: application/json" \
  7. --data '{
  8. "orgID": "'"${INFLUX_ORG_ID}"'",
  9. "name": "iot-center",
  10. "retentionRules": [
  11. {
  12. "type": "expire",
  13. "everySeconds": 86400,
  14. "shardGroupDurationSeconds": 0
  15. }
  16. ]
  17. }'

Write API

Write data to InfluxDB using an HTTP request to the InfluxDB API /write endpoint.

Query API

Query from InfluxDB using an HTTP request to the /query endpoint.