content/influxdb/v2/api-guide/influxdb-1x/write.md
The /write 1.x compatibility endpoint writes data to InfluxDB Cloud and InfluxDB OSS {{< current-version >}}
using patterns from the InfluxDB 1.x /write API endpoint.
Use the POST request method to write line protocol
to the /write endpoint.
{{% show-in "cloud,cloud-serverless" %}}
{{% note %}}
If you have an existing bucket that doesn't follow the database/retention-policy naming convention,
you must manually create a database and retention policy mapping
to write data to that bucket with the /write compatibility API.
{{% /note %}}
{{% /show-in %}}
{{% show-in "v2" %}}
Use one of the following authentication methods:
For more information, see Authentication.
{{% /show-in %}}
{{% show-in "cloud,cloud-serverless" %}}
{{% api/v1-compat/cloud/authentication %}}
{{% /show-in %}}
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.
{{% show-in "v2" %}}
(Optional) The 1.x username to authenticate the request. See query string authentication.
(Optional) The 1.x password to authenticate the request. See query string authentication.
{{% /show-in %}}
{{% show-in "cloud,cloud-serverless" %}}
(Optional) The InfluxDB Cloud username to authenticate the request. See query string authentication.
(Optional) The InfluxDB Cloud API token to authenticate the request. See query string authentication.
{{% /show-in %}}
({{< req >}}) The database to write data to. This is mapped to an InfluxDB bucket. See Database and retention policy mapping.
The retention policy to write data to. This is mapped to an InfluxDB bucket. See Database and retention policy mapping.
The precision of Unix timestamps in the line protocol.
Default is nanosconds (ns).
The following precisions are available:
ns - nanosecondsu or µ - microsecondsms - millisecondss - secondsm - minutesh - hours{{% show-in "v2" %}}
{{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|[email protected]" %}}
curl --request POST http://localhost:8086/write?db=DATABASE_NAME \
--user "USERNAME:PASSWORD_OR_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
{{% /code-placeholders %}}
{{% /show-in %}}
{{% show-in "cloud,cloud-serverless" %}} {{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|[email protected]" %}}
curl --request POST https://cloud2.influxdata.com/write?db=DATABASE_NAME \
--user "[email protected]:API_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
{{% /code-placeholders %}}
{{% /show-in %}}
{{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|[email protected]" %}}
curl --request POST http://localhost:8086/write?db=DATABASE_NAME \
--header "Authorization: Token API_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
{{% /code-placeholders %}}
{{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|[email protected]" %}}
curl --request POST "http://localhost:8086/write?db=DATABASE_NAME&rp=RETENTION_POLICY" \
--header "Authorization: Token API_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
{{% /code-placeholders %}}
{{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|[email protected]" %}}
curl --request POST http://localhost:8086/write?db=DATABASE_NAME \
--header "Authorization: Token API_TOKEN" \
--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"
{{% /code-placeholders %}}
{{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|[email protected]" %}}
curl --request POST "http://localhost:8086/write?db=DATABASE_NAME&precision=ms" \
--header "Authorization: Token API_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000"
{{% /code-placeholders %}}
{{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|[email protected]" %}}
curl --request POST http://localhost:8086/write?db=DATABASE_NAME \
--header "Authorization: Token API_TOKEN" \
--data-binary @path/to/line-protocol.txt
{{% /code-placeholders %}}
{{% show-in "v2" %}}
Replace the following:
DATABASE_NAME and RETENTION_POLICY{{% /code-placeholder-key %}}: the database and retention policy mapping (DBRP) for the InfluxDB v2 bucket that you want to write toUSERNAME{{% /code-placeholder-key %}}: your InfluxDB 1.x usernamePASSWORD_OR_TOKEN{{% /code-placeholder-key %}}: your InfluxDB 1.x password or InfluxDB API tokenAPI_TOKEN{{% /code-placeholder-key %}}: your InfluxDB API token{{% /show-in %}}
{{% show-in "cloud,cloud-serverless" %}}
Replace the following:
DATABASE_NAME and RETENTION_POLICY{{% /code-placeholder-key %}}: the database and retention policy mapping (DBRP) for the InfluxDB v2 bucket that you want to write to[email protected]{{% /code-placeholder-key %}}: the email address that you signed up withAPI_TOKEN{{% /code-placeholder-key %}}: your InfluxDB API token{{% /show-in %}}