Documentation

Use the InfluxDB v1 HTTP write API

Use the InfluxDB v1 HTTP API /write endpoint and InfluxQL to write data stored in InfluxDB Cloud Serverless. The /write endpoint provides compatibility for InfluxDB 1.x workloads that you bring to InfluxDB v3.

The v1 write and query APIs require mapping databases and retention policies to buckets.

Map databases and retention policies to buckets

The v1 write and query APIs require mapping databases and retention policies to buckets.

InfluxDB can autogenerate a bucket and DBRP mapping for a write request or you can create a bucket and DBRP before writing.

Autogenerate a bucket and DBRP mapping

To let InfluxDB autogenerate a bucket and an associated DBRP mapping, pass the following parameters when writing data to the v1 /write endpoint:

If no bucket exists with the name DATABASE_NAME/RETENTION_POLICY_NAME, InfluxDB creates a bucket and a DBRP before writing the data to the bucket.

To learn more about DBRP mapping, see the v1 API compatibility guide.

Create a bucket and DBRP mapping

To create a DBRP for a bucket:

  1. If it doesn’t already exist, create the bucket that you want to write to.
  2. Find the bucket ID for the bucket that you want to write to.
  3. Create a DBRP, which maps a database name and retention policy name to the bucket ID from the preceding step.

If the db=DATABASE_NAME and rp=RETENTION_POLICY parameters in your /write request map to an existing DBRP, InfluxDB writes to the mapped bucket.

Write to the v1 HTTP /write endpoint

POST https://cloud2.influxdata.com/write

Parameters

For InfluxDB Cloud Serverless v1 API /write requests, set parameters as listed in the following table:

Parameter Allowed in Ignored Value
consistency Query string Ignored N/A
db * Query string Honored Database (see how to map databases and retention policies to buckets)
precision Query string Honored Timestamp precision
rp Query string Honored Retention policy (see how to map databases and retention policies to buckets)
Authorization header or u and p Token
* = Required

Timestamp precision

Use one of the following precision values in v1 API /write requests:

  • ns: nanoseconds
  • us: microseconds
  • ms: milliseconds
  • s: seconds
  • m: minutes
  • h: hours

Data

In the request body, include the line protocol data that you want to write to the bucket.

Authorization

To authorize writes to an existing bucket, include a token that has write permission to the bucket. Use Token authentication or v1-compatible username and password authentication to include a token in the request.

For InfluxDB to autogenerate the bucket and DBRP, you must use a token, such as an All-access token, that has write permissions to buckets and DBRPs.

Tools for writing to the v1 API

When using the v1 API and associated tooling, pass the DBRP mapping’s database name and retention policy name in the request parameters.

The following tools work with the InfluxDB Cloud Serverless /write endpoint:

Telegraf

If you have existing v1 workloads that use Telegraf, you can use the InfluxDB v1.x influxdb Telegraf output plugin to write data.

See how to use Telegraf and the v2 API for new workloads that don’t already use the v1 API.

The following table shows outputs.influxdb plugin parameters and values for writing to the InfluxDB Cloud Serverless v1 API:

Parameter Ignored Value
database Honored Bucket name
retention_policy Honored Duration
username Ignored String or empty
password Honored API token with permission to write to the bucket
content_encoding Honored gzip (compressed data) or identity (uncompressed)
skip_database_creation Ignored N/A (see how to create a bucket)

To configure the v1.x output plugin for writing to InfluxDB Cloud Serverless, add the following outputs.influxdb configuration in your telegraf.conf file:

[[outputs.influxdb]]
  urls = ["https://cloud2.influxdata.com"]
  database = "DATABASE_NAME"
  skip_database_creation = true
  retention_policy = "
RETENTION_POLICY
"
username = "ignored" password = "
API_TOKEN
"
content_encoding = "gzip

Replace the following:

Other Telegraf configuration options

influx_uint_support: supported in InfluxDB v3.

For more plugin options, see influxdb on GitHub.

Interactive clients

To test InfluxDB v1 API writes interactively from the command line, use common HTTP clients such as cURL and Postman.

For production use cases, use tools such as client libraries that construct line protocol for you and provide batch writing options.

curl -i "https://cloud2.influxdata.com/write?db=
DATABASE_NAME
&rp=
RETENTION_POLICY
&precision=s"
\
--header "Authorization: Token
API_TOKEN
"
\
--header "Content-type: text/plain; charset=utf-8" \ --data-binary 'home,room=kitchen temp=72 1463683075'
curl -i "https://cloud2.influxdata.com/write?db=
DATABASE_NAME
&rp=
RETENTION_POLICY
&precision=s"
\
-user "ignored":"
API_TOKEN
"
\
--header "Content-type: text/plain; charset=utf-8" \ --data-binary 'home,room=kitchen temp=72 1463683075'
curl -i "https://cloud2.influxdata.com/write?db=
DATABASE_NAME
&rp=
RETENTION_POLICY
&precision=s"
\
--header "Content-type: text/plain; charset=utf-8" \ --data-urlencode "u=ignored" \ --data-urlencode "p=DATABASE_TOKEN" \ --data-binary 'home,room=kitchen temp=72 1463683075'

Replace the following:

v1 influx CLI (not supported)

Don’t use the v1 influx CLI with InfluxDB Cloud Serverless. While it may coincidentally work, it isn’t officially supported.

Client libraries

Use language-specific v1 client libraries and your custom code to write data to InfluxDB. v1 client libraries send data in line protocol syntax to the v1 API /write endpoint.

The following samples show how to configure v1 client libraries for writing to InfluxDB Cloud Serverless:

Create a v1 API client using the node-influx JavaScript client library:

const Influx = require('influx')

// Instantiate a client for writing to InfluxDB Cloud Serverless v1 API
const client = new Influx.InfluxDB({
  host: 'cloud2.influxdata.com',
  port: 443,
  protocol: 'https'
  database: '
BUCKET_NAME
'
,
username: 'ignored', password: '
API_TOKEN
'
}) // When calling write or query functions, specify the retention policy name in options.

Create a v1 API client using the influxdb-python Python client library:

from influxdb import InfluxDBClient

# Instantiate a client for writing to InfluxDB Cloud Serverless v1 API
client = InfluxDBClient(
  host='cloud2.influxdata.com',
  ssl=True,
  database='
DATABASE_NAME
'
,
username='', password='
API_TOKEN
'
headers={'Content-Type': 'text/plain; charset=utf-8'} ) # When calling write or query functions, specify the retention policy name in options.

Replace the following:


Was this page helpful?

Thank you for your feedback!


Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

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.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

InfluxDB Cloud Serverless