<commit_before>---
title: Write data with the InfluxDB API

menu:
  influxdb_1_8:
    weight: 10
    parent: Guides
alises:
  - /influxdb/v1.8/guides/writing_data/
---

Write data into InfluxDB using the [command line interface](/influxdb/v1.8/tools/shell/), [client libraries](/influxdb/v1.8/clients/api/), and plugins for common data formats such as [Graphite](/influxdb/v1.8/write_protocols/graphite/).

> **Note**: The following examples use `curl`, a command line tool that transfers data using URLs. Learn the basics of `curl` with the [HTTP Scripting Guide](https://curl.haxx.se/docs/httpscripting.html).

### Create a database using the InfluxDB API

To create a database send a `POST` request to the `/query` endpoint and set the URL parameter `q` to `CREATE DATABASE <new_database_name>`.
The example below sends a request to InfluxDB running on `localhost` and creates the `mydb` database:

```bash
curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb"
```

### Write data using the InfluxDB API

The InfluxDB API is the primary means of writing data into InfluxDB.

- To write to an existing database, send `POST` requests to the `/write` endpoint.
- To write to a database created in 1.8 or later using [InfluxDB client libraries (with InfluxDB 2.0 compatibility)](/influxdb/v1.8/tools/api-client-libraries/#client-libraries), send `POST` requests to the [`/api/v2/write` endpoint](/influxdb/v1.8/tools/api/#-client-libraries/#client-libraries).

For example, to write a single point to the `mydb` database.
The data consists of the [measurement](/influxdb/v1.8/concepts/glossary/#measurement) `cpu_load_short`, the [tag keys](/influxdb/v1.8/concepts/glossary/#tag-key) `host` and `region` with the [tag values](/influxdb/v1.8/concepts/glossary/#tag-value) `server01` and `us-west`, the [field key](/influxdb/v1.8/concepts/glossary/#field-key) `value` with a [field value](/influxdb/v1.8/concepts/glossary/#field-value) of `0.64`, and the [timestamp](/influxdb/v1.8/concepts/glossary/#timestamp) `1434055562000000000`.

```bash
curl -i -XPOST 'http://localhost:8086/write?db=mydb' 
--data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
```

Alternatively, to write data using the InfluxDB 2.0 compatible endpoint

```
curl -i -XPOST 'http://localhost:8086/api/v2/write?bucket=db/rp&precision=ns' \
  --header 'Authorization: Token username:password' \
  --data-raw 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
```

When writing points, you must specify an existing database in the `db` query parameter.
Points will be written to `db`'s default retention policy if you do not supply a retention policy via the `rp` query parameter.
See the [InfluxDB API Reference](/influxdb/v1.8/tools/api/#write-http-endpoint) documentation for a complete list of the available query parameters.

The body of the POST or [InfluxDB line protocol](/influxdb/v1.8/concepts/glossary/#influxdb-line-protocol) contains the time series data that you want to store. Data includes:

- **Measurement (required)**
- **Tags**: Strictly speaking, tags are optional but most series include tags to differentiate data sources and to make querying both easy and efficient.
Both tag keys and tag values are strings.
- **Fields (required)**: Field keys are required and are always strings, and, [by default](/influxdb/v1.8/write_protocols/line_protocol_reference/#data-types), field values are floats.
- **Timestamp**: Supplied at the end of the line in Unix time in nanoseconds since January 1, 1970 UTC - is optional. If you do not specify a timestamp, InfluxDB uses the server's local nanosecond timestamp in Unix epoch.
Time in InfluxDB is in UTC format by default.

### Configure gzip compression

InfluxDB supports gzip compression. To reduce network traffic, consider the following options:

* To accept compressed data from InfluxDB, add the `Accept-Encoding: gzip` header to InfluxDB API requests.

* To compress data before sending it to InfluxDB, add the `Content-Encoding: gzip` header to InfluxDB API requests.

For details about enabling gzip for client libraries, see your client library documentation.
<commit_msg>clarify alternative curl request to /api/v2/write<commit_after>---
title: Write data with the InfluxDB API

menu:
  influxdb_1_8:
    weight: 10
    parent: Guides
alises:
  - /influxdb/v1.8/guides/writing_data/
---

Write data into InfluxDB using the [command line interface](/influxdb/v1.8/tools/shell/), [client libraries](/influxdb/v1.8/clients/api/), and plugins for common data formats such as [Graphite](/influxdb/v1.8/write_protocols/graphite/).

> **Note**: The following examples use `curl`, a command line tool that transfers data using URLs. Learn the basics of `curl` with the [HTTP Scripting Guide](https://curl.haxx.se/docs/httpscripting.html).

### Create a database using the InfluxDB API

To create a database send a `POST` request to the `/query` endpoint and set the URL parameter `q` to `CREATE DATABASE <new_database_name>`.
The example below sends a request to InfluxDB running on `localhost` and creates the `mydb` database:

```bash
curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb"
```

### Write data using the InfluxDB API

The InfluxDB API is the primary means of writing data into InfluxDB.

- To write to an existing database, send `POST` requests to the `/write` endpoint.
- To write to a database created in 1.8 or later using [InfluxDB client libraries (with InfluxDB 2.0 compatibility)](/influxdb/v1.8/tools/api-client-libraries/#client-libraries), send `POST` requests to the [`/api/v2/write` endpoint](/influxdb/v1.8/tools/api/#-client-libraries/#client-libraries).

For example, to write a single point to the `mydb` database.
The data consists of the [measurement](/influxdb/v1.8/concepts/glossary/#measurement) `cpu_load_short`, the [tag keys](/influxdb/v1.8/concepts/glossary/#tag-key) `host` and `region` with the [tag values](/influxdb/v1.8/concepts/glossary/#tag-value) `server01` and `us-west`, the [field key](/influxdb/v1.8/concepts/glossary/#field-key) `value` with a [field value](/influxdb/v1.8/concepts/glossary/#field-value) of `0.64`, and the [timestamp](/influxdb/v1.8/concepts/glossary/#timestamp) `1434055562000000000`.

```bash
curl -i -XPOST 'http://localhost:8086/write?db=mydb'
--data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
```

Alternatively, to write data to InfluxDB 1.8+ using the InfluxDB 2.0 API, include the [`/api/v2/write` endpoint](/influxdb/v1.8/tools/api/#-client-libraries/#client-libraries) in your curl request:

```
curl -i -XPOST 'http://localhost:8086/api/v2/write?bucket=db/rp&precision=ns' \
  --header 'Authorization: Token <PASSWORD>:password' \
  --data-raw 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
```

When writing points, you must specify an existing database in the `db` query parameter.
Points will be written to `db`'s default retention policy if you do not supply a retention policy via the `rp` query parameter.
See the [InfluxDB API Reference](/influxdb/v1.8/tools/api/#write-http-endpoint) documentation for a complete list of the available query parameters.

The body of the POST or [InfluxDB line protocol](/influxdb/v1.8/concepts/glossary/#influxdb-line-protocol) contains the time series data that you want to store. Data includes:

- **Measurement (required)**
- **Tags**: Strictly speaking, tags are optional but most series include tags to differentiate data sources and to make querying both easy and efficient.
Both tag keys and tag values are strings.
- **Fields (required)**: Field keys are required and are always strings, and, [by default](/influxdb/v1.8/write_protocols/line_protocol_reference/#data-types), field values are floats.
- **Timestamp**: Supplied at the end of the line in Unix time in nanoseconds since January 1, 1970 UTC - is optional. If you do not specify a timestamp, InfluxDB uses the server's local nanosecond timestamp in Unix epoch.
Time in InfluxDB is in UTC format by default.

### Configure gzip compression

InfluxDB supports gzip compression. To reduce network traffic, consider the following options:

* To accept compressed data from InfluxDB, add the `Accept-Encoding: gzip` header to InfluxDB API requests.

* To compress data before sending it to InfluxDB, add the `Content-Encoding: gzip` header to InfluxDB API requests.

For details about enabling gzip for client libraries, see your client library documentation.

{'fraction_non_alphanumeric': 0.11024356135648526, 'fraction_numerical': 0.031231791166530708, 'mean_word_length': 4.744310575635877, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '812504', 'n_tokens_mistral': 2878, 'n_tokens_neox': 2631, 'n_words': 965}