This guide covers how to merge several PDFs into a single output file. To convert a file to PDF before merging it, see Convert, Copy and Move Documents. It assumes you're already familiar with the basic generation flow covered in Generate Document.
Only PDFs can be merged — every source must already be a PDF, and the output is always a PDF.
Each source is located by a urn and a loadMethod:
POST /documents/document/upload, or one Doctavian generated with deliveryMethod: "Storage" (use the generated document's urn).To upload PDFs to Storage, send them as multipart/form-data:
POST https://api.doctavian.com/v1/documents/document/upload
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: multipart/form-data
file: part-one.pdf
file: part-two.pdfThe response returns a storage id for each file, in the order you sent them — this is what you'll pass as urn in the merge request:
{
"result": {
"data": {
"files": [
{ "id": "e3b0c442-98fc-4e1a-8a3d-2c1b5f6e9a70", "fileName": "part-one.pdf" },
{ "id": "5d8e9f0a-1b2c-43d4-95e6-7f8a9b0c1d2e", "fileName": "part-two.pdf" }
]
}
}
}Uploaded files are kept for 24 hours. Accepted file types and size limits are in Supported File Formats.
Send a single call to POST /documents/document/merge with two sections:
urn, loadMethod and order, plus an optional removename (without extension), fileFormat (always "pdf"), deliveryMethod, and pathYou can also send externalContext (echoed back) and data.embedded — a JSON-serialized string of key-value pairs written into the merged PDF's document properties.
POST https://api.doctavian.com/v1/documents/document/merge
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"externalContext": { "caseId": "CASE-2026-0815" },
"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": "combined-contract",
"fileFormat": "pdf",
"deliveryMethod": "Storage",
"path": "root"
}
}order worksSources are merged in ascending order, starting at 1. order must run 1, 2, 3 … with no gaps — merging stops at the first missing number, so a gap (e.g. 1, 2, 4) or a source without order silently leaves sources out. This is not reported as an error, so check your numbering. Two sources with the same order fail the request.
For a Storage source, any remove value other than none deletes it after it is loaded; leave remove out or send "none" to keep it. OneDrive and Google Drive sources are never deleted by a merge. Sources are loaded before the merge runs, so a Storage source set for removal can already be gone if a later source fails the request.
The response gives the merged file's id:
{
"result": {
"statusCode": 201,
"data": {
"document": {
"deliveryMethod": "Storage",
"name": "combined-contract",
"fileFormat": "pdf",
"urn": "7c4e2a91-3b8d-4f60-9e15-a2d7c8b3f046"
}
}
},
"consumption": [ { "dimension": "documents-merged", "value": 2 } ],
"externalContext": { "caseId": "CASE-2026-0815" },
...
}For a Storage delivery, download the merged file within 24 hours with GET /documents/document/{urn}/download, using the returned urn. For a drive delivery, the response also carries uri and any sharing links you requested.
If the merge fails, the most common cause is a Storage source that is already gone — expired or removed by an earlier call. See the full merge request and response schema, and the error codes, in the API Reference.
For large merges, use POST /documents/document/merge/async. The body and every rule are identical; add the x-client-authorization header so Doctavian knows where to deliver the result.
POST https://api.doctavian.com/v1/documents/document/merge/async
Authorization: Bearer <token>
x-api-key: <api-key>
x-client-authorization: <client-token>
Content-Type: application/json
{
"externalContext": { "caseId": "CASE-2026-0815" },
"sourceDocuments": [
{ "urn": "e3b0c442-98fc-4e1a-8a3d-2c1b5f6e9a70", "loadMethod": "Storage", "order": 1 },
{ "urn": "5d8e9f0a-1b2c-43d4-95e6-7f8a9b0c1d2e", "loadMethod": "Storage", "order": 2 }
],
"targetDocument": {
"name": "combined-contract",
"fileFormat": "pdf",
"deliveryMethod": "Storage",
"path": "root"
}
}The call returns HTTP 200 with an empty body once the request is queued. The merge result — the same envelope as above, or an error envelope — is POSTed to your callback URL. See Handle Async Generation for handling callbacks, and Client Header for building the header.
Merge accepts PDF sources only. To merge a Word document, Excel workbook or PowerPoint deck, convert it to PDF first with document manage (POST /documents/document/manage), then use the returned urn as a Storage source here. Manage also copies and moves files between Storage, OneDrive and Google Drive. Note that a Storage source is always deleted once manage has loaded it. See Convert, Copy and Move Documents.
order controls the merged output — and that gaps and missing values silently drop sources