InfluxData Write API

Write time series data to [buckets](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#bucket).

OpenAPI Specification

influxdata-write-api-openapi.yml Raw ↑
openapi: 3.0.0
info:
  title: InfluxDB Cloud API Service Authorizations (API tokens) Authorizations (API tokens) Write API
  version: 2.0.1
  description: 'The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint.

    '
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
- url: /api/v2
security:
- TokenAuthentication: []
tags:
- name: Write
  description: 'Write time series data to [buckets](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#bucket).

    '
paths:
  /write:
    post:
      operationId: PostWrite
      tags:
      - Write
      summary: Write data
      description: "Writes data to a bucket.\n\nUse this endpoint to send data in [line protocol](https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/) format to InfluxDB.\n\n#### InfluxDB Cloud\n\n- Does the following when you send a write request:\n\n  1. Validates the request and queues the write.\n  2. If queued, responds with _success_ (HTTP `2xx` status code); _error_ otherwise.\n  3. Handles the delete asynchronously and reaches eventual consistency.\n\n  To ensure that InfluxDB Cloud handles writes and deletes in the order you request them,\n  wait for a success response (HTTP `2xx` status code) before you send the next request.\n\n  Because writes and deletes are asynchronous, your change might not yet be readable\n  when you receive the response.\n\n#### InfluxDB OSS\n\n- Validates the request and handles the write synchronously.\n- If all points were written successfully, responds with HTTP `2xx` status code;\n  otherwise, returns the first line that failed.\n\n#### Required permissions\n\n- `write-buckets` or `write-bucket BUCKET_ID`.\n\n *`BUCKET_ID`* is the ID of the destination bucket.\n\n#### Rate limits (with InfluxDB Cloud)\n\n`write` rate limits apply.\nFor more information, see [limits and adjustable quotas](https://docs.influxdata.com/influxdb/cloud/account-management/limits/).\n\n#### Related guides\n\n- [Write data with the InfluxDB API](https://docs.influxdata.com/influxdb/cloud/write-data/developer-tools/api)\n- [Optimize writes to InfluxDB](https://docs.influxdata.com/influxdb/cloud/write-data/best-practices/optimize-writes/)\n- [Troubleshoot issues writing data](https://docs.influxdata.com/influxdb/cloud/write-data/troubleshoot/)\n"
      requestBody:
        description: "In the request body, provide data in [line protocol format](https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/).\n\nTo send compressed data, do the following:\n\n  1. Use [GZIP](https://www.gzip.org/) to compress the line protocol data.\n  2. In your request, send the compressed data and the\n     `Content-Encoding: gzip` header.\n\n#### Related guides\n\n- [Best practices for optimizing writes](https://docs.influxdata.com/influxdb/cloud/write-data/best-practices/optimize-writes/)\n"
        required: true
        content:
          text/plain:
            schema:
              type: string
              format: byte
            examples:
              plain-utf8:
                value: 'airSensors,sensor_id=TLM0201 temperature=73.97038159354763,humidity=35.23103248356096,co=0.48445310567793615 1630424257000000000

                  airSensors,sensor_id=TLM0202 temperature=75.30007505999716,humidity=35.651929918691714,co=0.5141876544505826 1630424257000000000

                  '
      parameters:
      - $ref: '#/components/parameters/TraceSpan'
      - in: header
        name: Content-Encoding
        description: 'The compression applied to the line protocol in the request payload.

          To send a GZIP payload, pass `Content-Encoding: gzip` header.

          '
        schema:
          type: string
          description: 'Content coding.

            Use `gzip` for compressed data or `identity` for unmodified, uncompressed data.

            '
          default: identity
          enum:
          - gzip
          - identity
      - in: header
        name: Content-Type
        description: 'The format of the data in the request body.

          To send a line protocol payload, pass `Content-Type: text/plain; charset=utf-8`.

          '
        schema:
          type: string
          description: '`text/plain` is the content type for line protocol. `UTF-8` is the default character set.

            '
          default: text/plain; charset=utf-8
          enum:
          - text/plain
          - text/plain; charset=utf-8
      - in: header
        name: Content-Length
        description: 'The size of the entity-body, in bytes, sent to InfluxDB.

          If the length is greater than the `max body` configuration option,

          the server responds with status code `413`.

          '
        schema:
          type: integer
          description: The length in decimal number of octets.
      - in: header
        name: Accept
        description: "The content type that the client can understand.\nWrites only return a response body if they fail--for example,\ndue to a formatting problem or quota limit.\n\n#### InfluxDB Cloud\n\n  - Returns only `application/json` for format and limit errors.\n  - Returns only `text/html` for some quota limit errors.\n\n#### InfluxDB OSS\n\n  - Returns only `application/json` for format and limit errors.\n\n#### Related guides\n\n- [Troubleshoot issues writing data](https://docs.influxdata.com/influxdb/cloud/write-data/troubleshoot/)\n"
        schema:
          type: string
          description: Error content type.
          default: application/json
          enum:
          - application/json
      - in: query
        name: org
        description: "An organization name or ID.\n\n#### InfluxDB Cloud\n\n- Doesn't use the `org` parameter or `orgID` parameter.\n- Writes data to the bucket in the organization\n  associated with the authorization (API token).\n\n#### InfluxDB OSS\n\n- Requires either the `org` parameter or the `orgID` parameter.\n- If you pass both `orgID` and `org`, they must both be valid.\n- Writes data to the bucket in the specified organization.\n"
        required: true
        schema:
          type: string
          description: The organization name or ID.
      - in: query
        name: orgID
        description: "An organization ID.\n\n#### InfluxDB Cloud\n\n- Doesn't use the `org` parameter or `orgID` parameter.\n- Writes data to the bucket in the organization\n  associated with the authorization (API token).\n\n#### InfluxDB OSS\n\n- Requires either the `org` parameter or the `orgID` parameter.\n- If you pass both `orgID` and `org`, they must both be valid.\n- Writes data to the bucket in the specified organization.\n"
        schema:
          type: string
      - in: query
        name: bucket
        description: 'A bucket name or ID.

          InfluxDB writes all points in the batch to the specified bucket.

          '
        required: true
        schema:
          type: string
          description: The bucket name or ID.
      - in: query
        name: precision
        description: The precision for unix timestamps in the line protocol batch.
        schema:
          $ref: '#/components/schemas/WritePrecision'
      responses:
        '204':
          description: 'Success.


            #### InfluxDB Cloud


            - Validated and queued the request.

            - Handles the write asynchronously - the write might not have completed yet.


            #### InfluxDB OSS


            - Successfully wrote all points in the batch.


            #### Related guides


            - [How to check for write errors](https://docs.influxdata.com/influxdb/cloud/write-data/troubleshoot/)

            '
        '400':
          description: 'Bad request. The response body contains detail about the error.


            InfluxDB returns this error if the line protocol data in the request is malformed.

            The response body contains the first malformed line in the data, and indicates what was expected.

            For partial writes, the number of points written and the number of points rejected are also included.

            For more information, check the `rejected_points` measurement in your `_monitoring` bucket.


            #### InfluxDB Cloud


            - Returns this error for bucket schema conflicts.


            #### InfluxDB OSS


            - Returns this error if the `org` parameter or `orgID` parameter doesn''t match an organization.

            '
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LineProtocolError'
              examples:
                measurementSchemaFieldTypeConflict:
                  summary: (Cloud) field type conflict thrown by an explicit bucket schema
                  value:
                    code: invalid
                    message: 'partial write error (2 written): unable to parse ''air_sensor,service=S1,sensor=L1 temperature="90.5",humidity=70.0 1632850122'': schema: field type for field "temperature" not permitted by schema; got String but expected Float'
                orgNotFound:
                  summary: (OSS) organization not found
                  value:
                    code: invalid
                    message: 'failed to decode request body: organization not found'
        '401':
          $ref: '#/components/responses/AuthorizationError'
        '404':
          $ref: '#/components/responses/ResourceNotFoundError'
        '413':
          description: "The request payload is too large.\nInfluxDB rejected the batch and did not write any data.\n\n#### InfluxDB Cloud:\n\n - Returns this error if the payload exceeds the 50MB size limit.\n - Returns `Content-Type: text/html` for this error.\n\n#### InfluxDB OSS:\n\n - Returns this error only if the [Go (golang) `ioutil.ReadAll()`](https://pkg.go.dev/io/ioutil#ReadAll) function raises an error.\n - Returns `Content-Type: application/json` for this error.\n"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LineProtocolLengthError'
              examples:
                dataExceedsSizeLimitOSS:
                  summary: InfluxDB OSS response
                  value: '{"code":"request too large","message":"unable to read data: points batch is too large"}

                    '
            text/html:
              schema:
                type: string
              examples:
                dataExceedsSizeLimit:
                  summary: InfluxDB Cloud response
                  value: "<html>\n  <head><title>413 Request Entity Too Large</title></head>\n  <body>\n    <center><h1>413 Request Entity Too Large</h1></center>\n    <hr>\n    <center>nginx</center>\n  </body>\n</html>\n"
        '429':
          description: "Too many requests.\n\n#### InfluxDB Cloud\n\n  - Returns this error if a **read** or **write** request exceeds your plan's [adjustable service quotas](https://docs.influxdata.com/influxdb/cloud/account-management/limits/#adjustable-service-quotas)\n    or if a **delete** request exceeds the maximum [global limit](https://docs.influxdata.com/influxdb/cloud/account-management/limits/#global-limits).\n  - For rate limits that reset automatically, returns a `Retry-After` header that describes when to try the write again.\n  - For limits that can't reset (for example, **cardinality limit**), doesn't return a `Retry-After` header.\n\n  Rates (data-in (writes), queries (reads), and deletes) accrue within a fixed five-minute window.\n  Once a rate limit is exceeded, InfluxDB returns an error response until the current five-minute window resets.\n\n#### InfluxDB OSS\n\n  - Doesn't return this error.\n"
          headers:
            Retry-After:
              description: Non-negative decimal integer indicating seconds to wait before retrying the request.
              schema:
                type: integer
                format: int32
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          description: "Service unavailable.\n\n- Returns this error if\n  the server is temporarily unavailable to accept writes.\n- Returns a `Retry-After` header that describes when to try the write again.\n"
          headers:
            Retry-After:
              description: Non-negative decimal integer indicating seconds to wait before retrying the request.
              schema:
                type: integer
                format: int32
        default:
          $ref: '#/components/responses/GeneralServerError'
components:
  responses:
    AuthorizationError:
      description: "Unauthorized. The error may indicate one of the following:\n\n  * The `Authorization: Token` header is missing or malformed.\n  * The API token value is missing from the header.\n  * The token doesn't have sufficient permissions to write to this organization and bucket.\n"
      content:
        application/json:
          schema:
            properties:
              code:
                description: 'The HTTP status code description. Default is `unauthorized`.

                  '
                readOnly: true
                type: string
                enum:
                - unauthorized
              message:
                readOnly: true
                description: A human-readable message that may contain detail about the error.
                type: string
          examples:
            tokenNotAuthorized:
              summary: Token is not authorized to access a resource
              value:
                code: unauthorized
                message: unauthorized access
    GeneralServerError:
      description: Non 2XX error response from server.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ResourceNotFoundError:
      description: "Not found.\nA requested resource was not found.\nThe response body contains the requested resource type and the name value\n(if you passed it)--for example:\n\n- `\"organization name \\\"my-org\\\" not found\"`\n- `\"organization not found\"`: indicates you passed an ID that did not match\n   an organization.\n"
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            org-not-found:
              summary: Organization name not found
              value:
                code: not found
                message: organization name "my-org" not found
            bucket-not-found:
              summary: Bucket name not found
              value:
                code: not found
                message: bucket "air_sensor" not found
            orgID-not-found:
              summary: Organization ID not found
              value:
                code: not found
                message: organization not found
    InternalServerError:
      description: 'Internal server error.

        The server encountered an unexpected situation.

        '
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  parameters:
    TraceSpan:
      in: header
      name: Zap-Trace-Span
      description: OpenTracing span context
      example:
        trace_id: '1'
        span_id: '1'
        baggage:
          key: value
      required: false
      schema:
        type: string
  schemas:
    LineProtocolError:
      properties:
        code:
          description: Code is the machine-readable error code.
          readOnly: true
          type: string
          enum:
          - internal error
          - not found
          - conflict
          - invalid
          - empty value
          - unavailable
        message:
          readOnly: true
          description: Human-readable message.
          type: string
        op:
          readOnly: true
          description: Describes the logical code operation when the error occurred. Useful for debugging.
          type: string
        err:
          readOnly: true
          description: Stack of errors that occurred during processing of the request. Useful for debugging.
          type: string
        line:
          readOnly: true
          description: First line in the request body that contains malformed data.
          type: integer
          format: int32
      required:
      - code
    WritePrecision:
      type: string
      enum:
      - ms
      - s
      - us
      - ns
    LineProtocolLengthError:
      properties:
        code:
          description: Code is the machine-readable error code.
          readOnly: true
          type: string
          enum:
          - invalid
        message:
          readOnly: true
          description: Human-readable message.
          type: string
      required:
      - code
      - message
    Error:
      properties:
        code:
          description: code is the machine-readable error code.
          readOnly: true
          type: string
          enum:
          - internal error
          - not implemented
          - not found
          - conflict
          - invalid
          - unprocessable entity
          - empty value
          - unavailable
          - forbidden
          - too many requests
          - unauthorized
          - method not allowed
          - request too large
          - unsupported media type
        message:
          readOnly: true
          description: Human-readable message.
          type: string
        op:
          readOnly: true
          description: Describes the logical code operation when the error occurred. Useful for debugging.
          type: string
        err:
          readOnly: true
          description: Stack of errors that occurred during processing of the request. Useful for debugging.
          type: string
      required:
      - code
  securitySchemes:
    TokenAuthentication:
      type: apiKey
      name: Authorization
      in: header
      description: "Use the [Token authentication](#section/Authentication/TokenAuthentication)\nscheme to authenticate to the InfluxDB API.\n\nIn your API requests, send an `Authorization` header.\nFor the header value, provide the word `Token` followed by a space and an InfluxDB API token.\nThe word `Token` is case-sensitive.\n\n### Syntax\n\n`Authorization: Token INFLUX_API_TOKEN`\n\n### Example\n\n#### Use Token authentication with cURL\n\nThe following example shows how to use cURL to send an API request that uses Token authentication:\n\n```sh\ncurl --request GET \"INFLUX_URL/api/v2/buckets\" \\\n     --header \"Authorization: Token INFLUX_API_TOKEN\"\n```\n\nReplace the following:\n\n  - *`INFLUX_URL`*: your InfluxDB Cloud URL\n  - *`INFLUX_API_TOKEN`*: your [InfluxDB API token](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#token)\n\n### Related endpoints\n\n- [`/authorizations` endpoints](#tag/Authorizations-(API-tokens))\n\n### Related guides\n\n- [Authorize API requests](https://docs.influxdata.com/influxdb/cloud/api-guide/api_intro/#authentication)\n- [Manage API tokens](https://docs.influxdata.com/influxdb/cloud/security/tokens/)\n"
    BasicAuthentication:
      type: http
      scheme: basic
      description: "### Basic authentication scheme\n\nUse the HTTP Basic authentication scheme for InfluxDB `/api/v2` API operations that support it:\n\n### Syntax\n\n`Authorization: Basic BASE64_ENCODED_CREDENTIALS`\n\nTo construct the `BASE64_ENCODED_CREDENTIALS`, combine the username and\nthe password with a colon (`USERNAME:PASSWORD`), and then encode the\nresulting string in [base64](https://developer.mozilla.org/en-US/docs/Glossary/Base64).\nMany HTTP clients encode the credentials for you before sending the\nrequest.\n\n_**Warning**: Base64-encoding can easily be reversed to obtain the original\nusername and password. It is used to keep the data intact and does not provide\nsecurity. You should always use HTTPS when authenticating or sending a request with\nsensitive information._\n\n### Examples\n\nIn the examples, replace the following:\n\n- **`EMAIL_ADDRESS`**: InfluxDB Cloud username (the email address the user signed up with)\n- **`PASSWORD`**: InfluxDB Cloud [API token](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#token)\n- **`INFLUX_URL`**: your InfluxDB Cloud URL\n\n#### Encode credentials with cURL\n\nThe following example shows how to use cURL to send an API request that uses Basic authentication.\nWith the `--user` option, cURL encodes the credentials and passes them\nin the `Authorization: Basic` header.\n\n```sh\ncurl --get \"INFLUX_URL/api/v2/signin\"\n    --user \"EMAIL_ADDRESS\":\"PASSWORD\"\n```\n\n#### Encode credentials with Flux\n\nThe Flux [`http.basicAuth()` function](https://docs.influxdata.com/flux/v0.x/stdlib/http/basicauth/) returns a Base64-encoded\nbasic authentication header using a specified username and password combination.\n\n#### Encode credentials with JavaScript\n\nThe following example shows how to use the JavaScript `btoa()` function\nto create a Base64-encoded string:\n\n```js\nbtoa('EMAIL_ADDRESS:PASSWORD')\n```\n\nThe output is the following:\n\n```js\n'VVNFUk5BTUU6UEFTU1dPUkQ='\n```\n\nOnce you have the Base64-encoded credentials, you can pass them in the\n`Authorization` header--for example:\n\n```sh\ncurl --get \"INFLUX_URL/api/v2/signin\"\n    --header \"Authorization: Basic VVNFUk5BTUU6UEFTU1dPUkQ=\"\n```\n\nTo learn more about HTTP authentication, see\n[Mozilla Developer Network (MDN) Web Docs, HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication)._\n"
x-tagGroups:
- name: Overview
  tags:
  - Quick start
  - Authentication
  - Supported operations
  - Headers
  - Pagination
  - Response codes
- name: Popular endpoints
  tags:
  - Data I/O endpoints
  - Security and access endpoints
  - System information endpoints
- name: All endpoints
  tags: []