Documents

Document Merge

Markdown for LLMs
POST
/documents/document/merge

Merges several PDF files into one PDF and delivers it. List the files in sourceDocuments, each with its urn, the loadMethod that locates it (Storage, OneDrive or GoogleDrive) and its order. Every source must be a PDF. Describe the merged file in targetDocument: its name, fileFormat (always pdf), deliveryMethod and path.

order must run 1, 2, 3 … with no gaps. The sources are merged in ascending order, starting at 1 and stopping at the first missing number: a gap leaves out every source after it, a source without order counts as 0 and is left out, and if no source has order 1 the result is empty. None of these is reported as an error. Two sources with the same order fail the request with 500 MERGE_FUNCTION_FAILED. A source whose loadMethod is not one of the three is skipped without an error.

A Storage source is deleted after it is loaded when its remove is set to anything other than none; leave remove out or send none to keep it. OneDrive and GoogleDrive sources are never deleted. Sources are loaded before the merge runs, so a Storage source set for removal can already be gone when a later source fails the request.

The response is sent with HTTP 200, while result.statusCode in the body reports 201. To run the same merge without holding the connection open, use documents-document-merge-async.

Authorization

AuthorizationBearer <token>

JWT token to authenticate the request.

In: header

X-Api-Key<token>

API key, sent as a request header.

In: header

Request Body

application/json

Mandatory. The PDFs to merge under sourceDocuments and the merged file to produce under targetDocument, plus an optional externalContext.

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

curl -X POST "https://example.com/documents/document/merge" \  -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"    }  }'
{  "result": {    "statusCode": 201,    "message": "Created",    "data": {      "document": {        "deliveryMethod": "Storage",        "name": "Q3 Sales Report - Merged",        "fileFormat": "pdf",        "urn": "7c4e2a91-3b8d-4f60-9e15-a2d7c8b3f046"      }    }  },  "consumption": [    {      "dimension": "documents-merged",      "value": 2    }  ],  "externalContext": {    "id": "req-2026-0007421"  },  "origin": "POST https://api.doctavian.com/v1/documents/document/merge",  "dateTime": "2026-10-09T09:12:44.000Z",  "userId": "1fa93f1d-07e8-4e08-84e6-c0098f3b6ed5",  "operationId": "6d2b9f4e1a8c47d3b05e9c2a7f1d8b36"}
Empty
{  "error": {    "statusCode": 403,    "message": "Forbidden",    "innerErrors": [      {        "code": "LIMIT_BREACH",        "message": "Limit has been breached for DOCUMENTS. Current usage is 1000, limit is 1000 for period month.",        "userMessage": "Limit has been breached for DOCUMENTS. Current usage is 1000, limit is 1000 for period month."      }    ],    "externalErrors": []  },  "externalContext": {    "id": "req-2026-0007421"  },  "origin": "POST https://api.doctavian.com/v1/documents/document/merge",  "dateTime": "2026-10-09T09:12:44.000Z",  "userId": "1fa93f1d-07e8-4e08-84e6-c0098f3b6ed5",  "operationId": "2f8a5d1c9e3b47a6b0d4c7e2a9f1b583"}
{  "error": {    "statusCode": 500,    "message": "Internal Server Error",    "innerErrors": [      {        "code": "MERGE_FUNCTION_FAILED",        "message": "Failed to merge the documents.",        "userMessage": "There was an issue merging the documents. Please check the input data and try again.",        "eventId": "c51e8b37-6d2a-4f94-8e0b-2a7d4c9f1e63"      }    ],    "externalErrors": []  },  "externalContext": {    "id": "req-2026-0007421"  },  "origin": "POST https://api.doctavian.com/v1/documents/document/merge",  "dateTime": "2026-10-09T09:12:44.000Z",  "userId": "1fa93f1d-07e8-4e08-84e6-c0098f3b6ed5",  "operationId": "1b7e4d92a6c34f58b0e3d7a1c9f2e684"}