content/influxdb3/cloud-serverless/write-data/api/v1-http.md
Use the InfluxDB v1 HTTP API /write endpoint and InfluxQL to write data stored in {{< product-name >}}.
The /write endpoint provides compatibility for InfluxDB 1.x workloads that you bring to InfluxDB 3.
The v1 write and query APIs require mapping 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.
To let InfluxDB autogenerate a bucket and an associated DBRP mapping, pass the following parameters when writing data to the v1 /write endpoint:
db=DATABASE_NAME parameter.rp=RETENTION_POLICY_NAME parameter. Default retention policy name is autogen.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.
To create a DBRP for a bucket:
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 endpoint{{% api-endpoint endpoint="https://{{< influxdb/host >}}/write" method="post" %}}
For {{% product-name %}} v1 API /write requests, set parameters as listed in the following table:
| Parameter | Allowed in | Ignored | Value |
|---|---|---|---|
consistency | Query string | Ignored | N/A |
db {{% req " *" %}} | 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 |
{{% caption %}}{{% req " *" %}} = {{% req "Required" %}}{{% /caption %}}
Use one of the following precision values in v1 API /write requests:
ns: nanosecondsus: microsecondsms: millisecondss: secondsm: minutesh: hoursIn the request body, include the line protocol data that you want to write to the bucket.
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.
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 {{% product-name %}} /write endpoint:
If you have existing v1 workloads that use Telegraf,
you can use the InfluxDB v1.x influxdb Telegraf output plugin to write data.
[!Note] 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 {{% product-name %}} 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 {{% product-name %}}, add the following outputs.influxdb configuration in your telegraf.conf file:
{{% code-placeholders "API_TOKEN|RETENTION_POLICY" %}}
[[outputs.influxdb]]
urls = ["https://{{< influxdb/host >}}"]
database = "DATABASE_NAME"
skip_database_creation = true
retention_policy = "RETENTION_POLICY"
username = "ignored"
password = "API_TOKEN"
content_encoding = "gzip”
{{% /code-placeholders %}}
Replace the following:
DATABASE_NAME{{% /code-placeholder-key %}}: the databaseRETENTION_POLICY{{% /code-placeholder-key %}}: the retention policyAPI_TOKEN{{% /code-placeholder-key %}}: a token with sufficient permissions to the mapped bucketinflux_uint_support: supported in InfluxDB 3.
For more plugin options, see influxdb on GitHub.
To test InfluxDB v1 API writes interactively from the command line, use common HTTP clients such as cURL and Postman.
[!Note] For production use cases, use tools such as client libraries that construct line protocol for you and provide batch writing options.
{{< code-tabs-wrapper >}} {{% code-tabs %}} Token Auth Basic Auth Query String Auth {{% /code-tabs %}} {{% code-tab-content %}} {{% code-placeholders "DATABASE_NAME|API_TOKEN|RETENTION_POLICY" %}}
curl -i "https://{{< influxdb/host >}}/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'
{{% /code-placeholders %}} {{% /code-tab-content %}} {{% code-tab-content %}} {{% code-placeholders "DATABASE_NAME|API_TOKEN|RETENTION_POLICY" %}}
curl -i "https://{{< influxdb/host >}}/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'
{{% /code-placeholders %}} {{% /code-tab-content %}} {{% code-tab-content %}} {{% code-placeholders "DATABASE_NAME|API_TOKEN|RETENTION_POLICY" %}}
curl -i "https://{{< influxdb/host >}}/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'
{{% /code-placeholders %}} {{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
Replace the following:
DATABASE_NAME{{% /code-placeholder-key %}}: the databaseRETENTION_POLICY{{% /code-placeholder-key %}}: the retention policyAPI_TOKEN{{% /code-placeholder-key %}}: a token with sufficient permissions to the mapped bucketDon't use the v1 influx CLI with {{% product-name %}}.
While it may coincidentally work, it isn't officially supported.
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 {{% product-name %}}:
{{< tabs-wrapper >}} {{% tabs %}} Node.js Python {{% /tabs %}} {{% tab-content %}}
<!-- Start NodeJS -->Create a v1 API client using the node-influx JavaScript client library:
{{% code-placeholders "BUCKET_NAME|API_TOKEN|RETENTION_POLICY" %}}
const Influx = require('influx')
// Instantiate a client for writing to {{% product-name %}} v1 API
const client = new Influx.InfluxDB({
host: '{{< influxdb/host >}}',
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.
{{% /code-placeholders %}}
<!-- End NodeJS -->{{% /tab-content %}} {{% tab-content %}}
<!-- Start Python -->Create a v1 API client using the influxdb-python Python client library:
{{% code-placeholders "DATABASE_NAME|API_TOKEN|RETENTION_POLICY" %}}
from influxdb import InfluxDBClient
# Instantiate a client for writing to {{% product-name %}} v1 API
client = InfluxDBClient(
host='{{< influxdb/host >}}',
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.
{{% /code-placeholders %}}
<!-- End Python -->{{% /tab-content %}} {{< /tabs-wrapper >}}
Replace the following:
DATABASE_NAME{{% /code-placeholder-key %}}: the databaseRETENTION_POLICY{{% /code-placeholder-key %}}: the retention policyAPI_TOKEN{{% /code-placeholder-key %}}: a token with sufficient permissions to the specified bucket