Documents

Document Merge Async

Markdown for LLMs
POST
/documents/document/merge/async

Runs the same merge as documents-document-merge, but asynchronously. Every rule of the synchronous operation applies unchanged; see its description for the request.

This endpoint returns HTTP 200 with an empty body as soon as the request is accepted and queued. That response only acknowledges receipt; it does not mean the operation succeeded.

The result arrives at your callback URL, not in the response to this call. Once the operation finishes, Doctavian sends a POST to the URL formed by joining the iss and dest claims of the X-Client-Authorization token supplied on this request, authenticating itself through the external connector named by that token's connector_id claim.

On success the callback body is the DocumentMergeResponse envelope — the same body documents-document-merge returns. On failure it is the ErrorResponse envelope, carrying the failure's own code: unlike the synchronous operation, no …_FUNCTION_FAILED entry is added after it. Correlate a callback with its request through externalContext, which is echoed back unchanged.

A 400 from this endpoint means the request was rejected before being queued, so no callback follows it. Usage limits are checked once the request is processed, so a reached limit arrives at the callback as an ErrorResponse with LIMIT_BREACH, not as an HTTP 403 from this endpoint.

Authorization

AuthorizationBearer <token>

JWT token to authenticate the request.

In: header

X-Api-Key<token>

API key, sent as a request header.

In: header

Header Parameters

X-Client-Authorization?string

This does not authenticate the async request itself — that's Authorization. It authenticates Doctavian's callback to your service once the async result is ready.

Generate it by calling POST /common/client/token with the claims below inside a clientToken object. That endpoint signs and encrypts the payload for you and returns the ready-to-use token in result.data.clientToken.token — you never construct or sign this token yourself.

Required claims: connector_id (the id of the external connector, a GUID, that Doctavian uses to authenticate to your service), sub (a placeholder kept for backward compatibility, whose value Doctavian does not use — copy the connector_id value into it), iss (base URL of the service receiving the callback), dest (the callback route, e.g. /temp/callback — combined with iss to form the full callback URL). Optional claims: oid,client_id,full_name, email, locale, zoneinfo. You don't need to set iat or exp — the token endpoint handles timing.

iss and dest cannot resolve back to Doctavian's own API — that combination is rejected to prevent a callback loop.

If this header is missing on an async request, the response is 400 X_CLIENT_AUTH_ERROR ("header is missing for async operations").

Request Body

application/json

Mandatory. The same body as documents-document-merge.

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

curl -X POST "https://example.com/documents/document/merge/async" \  -H "X-Client-Authorization: eyJhbGciOiJIUzI1NiJ9.example-client-callback-token" \  -H "Content-Type: application/json" \  -d '{    "externalContext": {      "id": "req-2026-0007421"    },    "sourceDocuments": [      {        "urn": "e3b0c442-98fc-4e1a-8a3d-2c1b5f6e9a70",        "loadMethod": "Storage",        "order": 1,        "remove": "none"      },      {        "urn": "5d8e9f0a-1b2c-43d4-95e6-7f8a9b0c1d2e",        "loadMethod": "Storage",        "order": 2,        "remove": "none"      }    ],    "targetDocument": {      "name": "Q3 Sales Report - Merged",      "fileFormat": "pdf",      "deliveryMethod": "Storage",      "path": "root"    }  }'
Empty
{  "error": {    "statusCode": 400,    "message": "Bad Request",    "innerErrors": [      {        "code": "X_CLIENT_AUTH_ERROR",        "message": "header is missing for async operations",        "userMessage": "This request can't be accepted without a callback authorization header."      }    ],    "externalErrors": []  },  "externalContext": {    "id": "req-2026-0007421"  },  "origin": "POST https://api.doctavian.com/v1/documents/document/merge/async",  "dateTime": "2026-07-14T09:30:00.000Z",  "userId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d",  "operationId": "38a1de72cef5aba1c0b26dd712239827"}