API Quick Start
This page documents an earlier version of InfluxDB OSS. InfluxDB 3 Core is the latest stable version.
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.
Use InfluxDB 1.x API clients with 2.7
If you need to use InfluxDB 2.7 with InfluxDB 1.x API clients and integrations, see the 1.x compatibility guide.
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. InfluxDB filters API requests and response data based on the permissions associated with the token.
Before exploring the API, use the
influx
CLI or the InfluxDB UI to create an initial API token for your application.Include your API token in an
Authorization: Token API_TOKEN
HTTP header with each request–for example:
# Use a token to authorize a GET request to the InfluxDB API.
# List buckets in your organization that the token can read.
curl -X GET "http://localhost:8086/api/v2/buckets" \
--header 'Accept: application/json' \
--header 'Authorization: Token API_TOKEN'
/**
* Use a token to authorize a GET request to the InfluxDB API.
* List buckets in your organization that the token can read.
*/
const https = require('https');
function listBuckets() {
const options = {
host: 'localhost:8086',
path: "/api/v2/buckets",
headers: {
'Authorization': 'Token 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();
}
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 your InfluxDB instance. To use the API to create a bucket, send a request to the following endpoint:
curl --request POST \
"http://localhost:8086/api/v2/buckets" \
--header "Authorization: Token API_TOKEN" \
--json '{
"orgID": "'"ORG_ID"'",
"name": "BUCKET_NAME",
"retentionRules": [
{
"type": "expire",
"everySeconds": RETENTION_PERIOD_SECONDS,
"shardGroupDurationSeconds": 0
}
]
}'
Replace the following placeholders with your values:
API_TOKEN
- your token.ORG_ID
- the ID of the organization that owns the bucket.BUCKET_NAME
- the name of the bucket to create.- Optional:
RETENTION_PERIOD_SECONDS
- the retention period (in number of seconds) to retain data in the bucket. Default is0
(infinite retention).- For example,
31536000
(1 year) or604800
(7 days).
- For example,
For more information, see Create a bucket.
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!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support. Customers using a trial license can email trial@influxdata.com for assistance.