# SubmitDocument

Submits a document to Avalara E-Invoicing API

`POST /documents`

**API:** Avalara E-Invoicing API
**Tag:** Documents
**API Version:** 1.6
**Base URL:** https://api.sbx.avalara.com/einvoicing
**Authentication:** Bearer token

Source: https://developer.avalara.com/products/e-invoicing/api/v1.6/methods/Documents/SubmitDocument/

## Description

When a UBL document is sent to this endpoint, it generates a document in the required format as mandated by the specified country. Additionally, it initiates the workflow to transmit the generated document to the relevant tax authority, if necessary.The response from the endpoint contains a unique document ID, which can be used to request the status of the document and verify if it was successfully accepted at the destination.Furthermore, the unique ID enables the download of a copy of the generated document for reference purposes.

## Parameters

| Name | Type | In | Required | Description |
|---|---|---|---|---|
| `avalara-version` | string | header | Yes | Header that specifies the API version to use (for example "1.6"). |
| `X-Avalara-Client` | string | header | No | Optional header for a client identifier string used for diagnostics (for example "Fingerprint"). |
| `Idempotency-Key` | string | header | No | Optional key that makes the submission safely retryable. Must be a UUID (RFC 9562), version 4.

**Scope.** The key is unique per customer account: the same key used by a different customer account is a different key. It is independent of `documentId` and is retained for the lifetime of the document it created. It is only used for this operation; use the `documentId` for status checks and downloads.

**Replay.** A repeat of a key is judged on a dedupe key that the platform generates from certain core attributes of the document. If the customer account, the key and the document (as identified by that dedupe key) all match an earlier submission, no new document is created and the original `documentId` is returned with `201` and the response header `Idempotent-Replayed: true`.

**Conflict.** If the customer account and key match but the document's core attributes differ from the first submission, the request is rejected with `422` and nothing is created.

**Edited document, same core attributes.** If a resubmission changes the document but its core attributes stay the same, it is treated as a replay: the original `documentId` is returned and the change is **not** applied.

**Guidance.** Use a **new** `Idempotency-Key` whenever you intend to send a different or modified document. Reuse a key only to retry the identical submission after a lost response.

May also be supplied as the `Idempotency-Key` query parameter; if both are supplied they must match. |
| `Idempotency-Key` | string | query | No | Query parameter equivalent of the `Idempotency-Key` header. Must be a UUID (RFC 9562), version 4. The same scope, replay and `422` rules apply: the key is unique per customer account, and you should use a new key for any different or modified document. If both are supplied they must match, otherwise the request is rejected with `400`. |

## Request Body

**Content-Type:** `multipart/form-data`
**Schema:** `SubmitDocument`

Allows submission of a document.

| Property | Type | Required | Description |
|---|---|---|---|
| `metadata` | object | **Yes** | Key value pairs of metadata for a document submission {  "workflowId": "partner-einvoicing", "dataFormat": "ubl-invoice", "dataFormatVersion": "2.1", "countryCode": "SA", "countryMandate": "SA-Phase1-B2B" } |
| `data` | object | **Yes** | The document to be submitted, as indicated by the metadata fields 'dataFormat' and 'dataFormatVersion' |

## Responses

| Status | Description | Schema |
|---|---|---|
| 201 | Returns a unique documentId for the submitted document. When the request carried an `Idempotency-Key` that the same customer account already used for the same document (as identified by a dedupe key the platform generates from certain core attributes of the document), the original documentId is returned and no new document is created; the response then also carries `Idempotent-Replayed: true`. If the resubmitted document was edited but its core attributes are unchanged, it is still treated as a replay and the edit is not applied. Use a new `Idempotency-Key` to send a different or modified document. | `DocumentSubmitResponse` |
| 400 | Bad request. Also returned when the `Idempotency-Key` is not a version 4 UUID, or when the header and query parameter values differ. |  |
| 401 | Unauthorized. |  |
| 403 | Forbidden. | `ForbiddenError` |
| 409 | Conflict. A previous submission with the same `Idempotency-Key` is still being processed. Retry after a short delay. |  |
| 422 | Unprocessable Entity. The same customer account already used this `Idempotency-Key` for a document whose core attributes differ from this one. Nothing is created. Use a new `Idempotency-Key` to send a different or modified document. |  |

### 201 Response: `DocumentSubmitResponse`

Returns the unique ID of a successful document submission

| Property | Type | Required | Description |
|---|---|---|---|
| `id` | string | No | Unique ID for this document that can be used for status checking and file downloads. This is a UID created by the Avalara E-Invoicing platform. Example: `52f60401-44d0-4667-ad47-4afe519abb53`. |

## Example Request

```bash
curl -X POST "https://api.sbx.avalara.com/einvoicing/documents" \
  -H "Authorization: Basic <credentials>" \
  -H "Accept: application/json" \
  -d '{
  "metadata": {
    "workflowId": "partner-einvoicing",
    "dataFormat": "ubl-invoice",
    "dataFormatVersion": "2.1",
    "outputDataFormat": "ubl-invoice",
    "outputDataFormatVersion": "2.1",
    "countryCode": "SA",
    "countryMandate": "SA-Phase1-B2B"
  },
  "data": {}
}'
```