# addDocumentVersion mutation


`addDocumentVersion` is a GraphQL mutation of the Chameleoon MAX API. Send it as `POST https://max-api.chameleoon.sk/api/v1/graphql` with your API key, see [Chameleoon MAX](/chameleoon-max).

Makes an uploaded file the document's next version, which becomes its current version. Call it
when a document you attached changes, for example a corrected delivery note.

#### Permissions

Requires the permission to write the document's target, with that target in your API key's
scope:

- `order.write` for a sales order's document.
- `invoice.sync` for an invoice's document.

Without it, the document is `NOT_FOUND` on `documentId`.

#### Repeated calls

`requestId` works as on [`attachDocument`](/chameleoon-max/mutation/attach-document). The same bytes as the current version
return `applied: false` and make no version.

#### Errors

- `CONFLICT` with `extensions.reason` `DOCUMENT_REMOVED` when the document was removed.
- Otherwise the same refusals as [`attachDocument`](/chameleoon-max/mutation/attach-document): `ORDER_STATUS`,
  `FILE_ALREADY_ATTACHED`, `NOT_FOUND` with field `documentId` or `fileId`, and
  `REQUEST_ID_REUSED`.
- On an invoice's document, the refusals of [`attachInvoiceDocument`](/chameleoon-max/mutation/attach-invoice-document) apply instead
  of `ORDER_STATUS`: `CONFLICT` with `extensions.reason` `INVOICE_REMOVED` when the invoice was
  removed in its accounting system.

#### Good to know

- On an invoice's document, a new version brings the document's `externalId` and
  `externalNumber` up to date with the invoice's.

> An error whose path runs below this field does not mean the call failed: the version was
> added, so do not retry. See [`Mutation`](/chameleoon-max/mutations).

## Arguments

- `input`: [`AddDocumentVersionInput!`](/chameleoon-max/type/add-document-version-input) · required

## Returns

[`AddDocumentVersionResult!`](/chameleoon-max/type/add-document-version-result)

## Example

**Mutation**

```graphql
mutation addDocumentVersion($input: AddDocumentVersionInput!) {
  addDocumentVersion(input: $input) {
    applied
    document {
      id
      kind
      title
      externalId
      externalNumber
      createdAt
    }
  }
}
```

**Variables**

```json
{
  "input": {
    "requestId": "example",
    "documentId": "00000000-0000-4000-8000-000000000001",
    "fileId": "00000000-0000-4000-8000-000000000001"
  }
}
```

**Response**

```json
{
  "data": {
    "addDocumentVersion": {
      "applied": true,
      "document": {
        "id": "00000000-0000-4000-8000-000000000001",
        "kind": "INVOICE",
        "title": "example",
        "externalId": "example",
        "externalNumber": "example",
        "createdAt": "2026-01-01T00:00:00Z"
      }
    }
  }
}
```

Values are illustrative: replace IDs and codes with your own before you send the call.
