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 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.0 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

Before diving into the API, use the InfluxDB UI to create an initial authentication token for your application.

InfluxDB uses authentication tokens to authorize API requests. Include your authentication token as an Authorization header in each request.

Example

#######################################
# 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 YourAuthToken" \
  --header 'Content-type: application/json' \
  --data-urlencode "db=mydb" \
  --data-urlencode "q=SELECT * FROM cpu_usage"

/**
  * 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 YourAuthToken',
      '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();
}

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.

Example

INFLUX_TOKEN=YourAuthToken
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
      }
    ],
  }'

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.


Set your InfluxDB URL

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.