docs-v2/content/influxdb/v2.0/reference/api/influxdb-1x/write.md

3.8 KiB
Raw Blame History

title list_title description menu weight influxdb/v2.0/tags products list_code_example related
/write 1.x compatibility API /write The `/write` 1.x compatibilty endpoint writes data to InfluxDB 2.0 using patterns from the InfluxDB 1.x `/write` API endpoint.
influxdb_2_0_ref
name parent
/write 1.x compatibility
301
write
cloud
<pre> <span class="api post">POST</span> https://cloud2.influxdata.com/write </pre>
/influxdb/v2.0/reference/syntax/line-protocol

The /write 1.x compatibilty endpoint writes data to InfluxDB 2.0 using patterns from the InfluxDB 1.x /write API endpoint. Use the POST request method to write line protocol to the /write endpoint.

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

Authentication

Use basic authentication or token authentication. For more information, see Authentication.

Request body

Include your line protocol in the request body. Binary encode the line protocol to prevent unintended formatting. The examples below use the curl --data-binary flag to binary encode the line protocol.

Query string parameters

db

Required The database to write data to. This is mapped to an InfluxDB 2.0 bucket. See Database and retention policy mapping.

rp

The retention policy to write data to. This is mapped to an InfluxDB 2.0 bucket. See Database and retention policy mapping.

precision

The precision of Unix timestamps in the line protocol. Default is nanosconds (ns). The following precisions are available:

  • ns - nanoseconds
  • u or µ - microseconds
  • ms - milliseconds
  • s - seconds
  • m - minutes
  • h - hours

Write examples

Write data using basic authentication
curl -XPOST https://cloud2.influxdata.com/write?db=mydb \
  -H "Authorization: Basic username:YourAuthToken" \
  --data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
Write data to a non-default retention policy
curl -XPOST https://cloud2.influxdata.com/write?db=mydb&rp=customrp \
  -H "Authorization: Basic username:YourAuthToken" \
  --data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
Write multiple lines of line protocol
curl -XPOST https://cloud2.influxdata.com/write?db=mydb \
  -H "Authorization: Token YourAuthToken" \
  --data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000
measurement,host=host2 field1=14i,field2=12.7 1577836800000000000
measurement,host=host3 field1=5i,field2=6.8 1577836800000000000"
Write data with millisecond Unix timestamps
curl -XPOST https://cloud2.influxdata.com/write?db=mydb&precision=ms \
  -H "Authorization: Token YourAuthToken" \
  --data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000"
Use curl to write data from a file
curl -XPOST https://cloud2.influxdata.com/write?db=mydb \
  -H "Authorization: Token YourAuthToken" \
  --data-binary @path/to/line-protocol.txt