Use InfluxDB API

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

RequirementInclude by
OrganizationUse the org query parameter in your request URL.
BucketUse the bucket query parameter in your request URL.
PrecisionUse the precision query parameter in your request URL.
Authentication tokenUse the Authorization: Token header.
Line protocolPass as plain text in your request body.

Example API write request

Below is an example API write request using curl. The URL depends on the version and location of your InfluxDB 2.0 instance (see InfluxDB URLs).

To compress data when writing to InfluxDB, set the Content-Encoding header to gzip. Compressing write requests reduces network bandwidth, but increases server-side load.

Uncompressed Compressed

  1. curl --request POST "http://localhost:8086/api/v2/write?org=YOUR_ORG&bucket=YOUR_BUCKET&precision=s" \
  2. --header "Authorization: Token YOURAUTHTOKEN" \
  3. --data-raw "
  4. mem,host=host1 used_percent=23.43234543 1556896326
  5. mem,host=host2 used_percent=26.81522361 1556896326
  6. mem,host=host1 used_percent=22.52984738 1556896336
  7. mem,host=host2 used_percent=27.18294630 1556896336
  8. "
  1. curl --request POST "http://localhost:8086/api/v2/write?org=YOUR_ORG&bucket=YOUR_BUCKET&precision=s" \
  2. --header "Authorization: Token YOURAUTHTOKEN" \
  3. --header "Content-Encoding: gzip" \
  4. --data-raw "
  5. mem,host=host1 used_percent=23.43234543 1556896326
  6. mem,host=host2 used_percent=26.81522361 1556896326
  7. mem,host=host1 used_percent=22.52984738 1556896336
  8. mem,host=host2 used_percent=27.18294630 1556896336
  9. "

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