Write data with the InfluxDB API

Write data to InfluxDB using an HTTP request to the InfluxDB API /api/v2/write endpoint. Use the POST request method and include the following in your request:

Requirement Include by
Organization Use the org query parameter in your request URL.
Bucket Use the bucket query parameter in your request URL.
Timestamp precision Use the precisionquery parameter in your request URL. Default is ns.
API token Use the Authorization: Token YOUR_API_TOKEN header.
Line protocol Pass as plain text in your request body.

Send a write request

The URL in the examples depends on the version and location of your InfluxDB 2.7 instance. Customize URLs in examples

curl --request POST \
"http://localhost:8086/api/v2/write?org=YOUR_ORG&bucket=YOUR_BUCKET&precision=ns" \
  --header "Authorization: Token YOUR_API_TOKEN" \
  --header "Content-Type: text/plain; charset=utf-8" \
  --header "Accept: application/json" \
  --data-binary '
    airSensors,sensor_id=TLM0201 temperature=73.97038159354763,humidity=35.23103248356096,co=0.48445310567793615 1630424257000000000
    airSensors,sensor_id=TLM0202 temperature=75.30007505999716,humidity=35.651929918691714,co=0.5141876544505826 1630424257000000000
'use strict'
/** @module write
 * Writes a data point to InfluxDB using the Javascript client library with Node.js.

import { InfluxDB, Point } from '@influxdata/influxdb-client'

/** Environment variables **/
const url = process.env.INFLUX_URL
const token = process.env.INFLUX_TOKEN
const org = process.env.INFLUX_ORG
const bucket = process.env.INFLUX_BUCKET

 * Instantiate the InfluxDB client
 * with a configuration object.
const influxDB = new InfluxDB({ url, token })

 * Create a write client from the getWriteApi method.
 * Provide your `org` and `bucket`.
const writeApi = influxDB.getWriteApi(org, bucket)

 * Apply default tags to all points.
writeApi.useDefaultTags({ region: 'west' })

 * Create a point and write it to the buffer.
const point1 = new Point('temperature')
  .tag('sensor_id', 'TLM01')
  .floatField('value', 24.0)
console.log(` ${point1}`)


 * Flush pending writes and close writeApi.
writeApi.close().then(() => {
  console.log('WRITE FINISHED')
Use gzip compression with the InfluxDB API

When using the InfluxDB API /api/v2/write endpoint to write data, compress the data with gzip and set the Content-Encoding header to gzip. Compression reduces network bandwidth, but increases server-side load.

echo "airSensors,sensor_id=TLM0201 temperature=73.97038159354763,humidity=35.23103248356096,co=0.48445310567793615 1630525358 
  airSensors,sensor_id=TLM0202 temperature=75.30007505999716,humidity=35.651929918691714,co=0.5141876544505826 1630525358" | gzip > air-sensors.gzip

curl --request POST \
"http://localhost:8086/api/v2/write?org=YOUR_ORG&bucket=YOUR_BUCKET&precision=ns" \
  --header "Authorization: Token YOUR_API_TOKEN" \
  --header "Content-Encoding: gzip" \
  --header "Content-Type: text/plain; charset=utf-8" \
  --header "Accept: application/json" \
  --data-binary @air-sensors.gzip

For information about InfluxDB API response codes, see InfluxDB API Write documentation.

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.

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: