Documentation

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 guides you through the most commonly used API methods.

For detailed documentation on the entire API, see the InfluxDB v2 API Reference.

If you need to use InfluxDB 2.7 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 and Authorization Token (API 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 Authorization: Token YOUR_API_TOKEN HTTP header with each request.

#######################################
# Use a token in the Authorization header
# to authenticate with the InfluxDB 2.x API.
#######################################

curl --get "http://localhost:8086/api/v2" \
  --header "Authorization: Token YOUR_API_TOKEN" \
  --header 'Content-type: application/json' \
  --data-urlencode "db=mydb" \
  --data-urlencode "q=SELECT * FROM cpu_usage"
  • Copy
  • Fill window
/**
  * Use a token in the Authorization header
  * to authenticate with the InfluxDB 2.x API.
  */

const https = require('https');

function queryWithToken() {

  const options = {
    host: 'localhost:8086',
    path: "/api/v2",
    headers: {
      'Authorization': 'Token YOUR_API_TOKEN',
      'Content-type': 'application/json'
    },
  };

  const request = https.get(options, (response) => {
    let rawData = '';
    response.on('data', () => {
      response.on('data', (chunk) => { rawData += chunk; });
    })
    response.on('end', () => {
      console.log(rawData);
    })
  });

  request.end();
}
  • Copy
  • Fill window

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.

INFLUX_TOKEN=YOUR_API_TOKEN
INFLUX_ORG_ID=YOUR_ORG_ID

curl --request POST \
  "http://localhost:8086/api/v2/buckets" \
  --header "Authorization: Token ${INFLUX_TOKEN}" \
  --header "Content-type: application/json" \
  --data '{
    "orgID": "'"${INFLUX_ORG_ID}"'",
    "name": "iot-center",
    "retentionRules": [
      {
        "type": "expire",
        "everySeconds": 86400,
        "shardGroupDurationSeconds": 0
      }
    ]
  }'
  • Copy
  • Fill window

Write API

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

Query API

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


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

Now Generally Available

InfluxDB 3 Core and Enterprise

Start fast. Scale faster.

Get the Updates

InfluxDB 3 Core is an open source, high-speed, recent-data engine that collects and processes data in real-time and persists it to local disk or object storage. InfluxDB 3 Enterprise builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries and optimized storage. A free tier of InfluxDB 3 Enterprise is available for non-commercial at-home or hobbyist use.

For more information, check out: