> **Source:** https://knowledge.leegality.com/document-execution/api/fetch-document-binary > **Site:** Leegality Knowledge Base — https://knowledge.leegality.com > **About:** Leegality is a document execution platform covering eSigning, stamps, NeSL, workflows, and REST API integration. > **Navigation:** Every article on this site has a plain-text version at `.txt` (this format). To get an index of all articles with their `.txt` links, read: https://knowledge.leegality.com/llms.txt > **AI Guide:** For instructions on how to navigate this knowledge base as an AI agent, read: https://knowledge.leegality.com/ai-readable.txt --- # GET /v3.1/document/fetchDocument — Fetch document (binary) Downloads the signed document, audit trail, sender attachments, or invitee supporting documents in **raw binary format**. **Authentication:** `X-Auth-Token` header required on every request. ## Request URL ``` GET https://app1.leegality.com/api/v3.1/document/fetchDocument?documentId={documentId}&documentDownloadType={documentDownloadType}&supportDocumentUrl={supportDocumentUrl}&index={index} ``` **Environments:** - Production: `https://app1.leegality.com/api/v3.1/document/fetchDocument` - Sandbox: `https://sandbox.leegality.com/api/v3.1/document/fetchDocument` --- ## Parameters | Name | In | Required | Type | Description | Example | |------|----|----------|------|-------------|---------| | `documentId` | query | Yes | string | The unique Document ID generated by Leegality when the eSigning request was created. Can also be retrieved from the Leegality dashboard. **Note:** `DOCUMENT`, `ATTACHMENT`, and `SUPPORTING_DOCUMENT` types can be fetched at any document stage. `AUDIT_TRAIL` requires the document to be fully completed. | — | | `documentDownloadType` | query | Yes | string | The type of file to download. Only one value can be passed per request — passing multiple values returns error `document.download.type`. **Possible values:** - `DOCUMENT` — The signed PDF document (Content-Type: `application/pdf`). Available at any document stage. - `AUDIT_TRAIL` — The audit trail generated by Leegality (Content-Type: `application/pdf`). Only available after the document is fully completed; returns error `document.not.completed` otherwise. - `ATTACHMENT` — Reference attachments uploaded by the sender (requires `index`). Available at any document stage. - `SUPPORTING_DOCUMENT` — Supporting documents uploaded by an invitee (requires `supportDocumentUrl` and `index`). Available at any document stage. **Note:** Values are **case-sensitive** and must be uppercase. Lowercase or invalid values return error code `document.download.type`. | — | | `supportDocumentUrl` | query | No | string | The invitation URL of the invitee whose supporting documents you want to fetch. Accepts either the full invitation URL (e.g., `https://sandbox.leegality.com/sign/544bf18f-...`) or just the UUID portion (e.g., `544bf18f-91b8-4afb-96ee-8ff1927a2726`). **Required when** `documentDownloadType` = `SUPPORTING_DOCUMENT`. Ignored for other `documentDownloadType` values. | — | | `index` | query | No | integer | The 0-based index of the attachment or supporting document to fetch. **Example:** Pass `0` for the first file, `1` for the second, and so on. **Required when** `documentDownloadType` = `ATTACHMENT` or `SUPPORTING_DOCUMENT`. Ignored for `DOCUMENT` and `AUDIT_TRAIL` types. **Error codes:** - `index.not.negative` — Returned if a negative value is passed - `index.out.of.bound` — Returned if the index exceeds the number of available files - `no.attachments.exists` — Returned if no attachments exist for the document | — | --- ## Responses ### 200 — **On success:** Returns the raw binary file with the appropriate Content-Type header (`application/pdf` for documents and audit trails; varies for attachments and supporting documents). **On error:** Returns a JSON response with `status: 0` and an error code in `messages[].code`. **All errors are returned with HTTP 200** — use the `status` field and `messages[].code` to detect failures, not the HTTP status code. | `messages[].code` | `messages[].message` | |---|---| | `document.not.completed` | Document has not been completed yet. Audit trail cannot be downloaded for incomplete documents. | | `document.download.type` | Document Type (AUDIT_TRAIL,DOCUMENT) Not Supported. Please enter value as : [DOCUMENT, AUDIT_TRAIL, ATTACHMENT, SUPPORTING_DOCUMENT]. | Error response returned when the fetch request fails. On success, this endpoint returns raw binary data (not JSON), so this schema only applies to error responses. | Field | Type | Required | Description | Example | |-------|------|----------|-------------|---------| | `status` | integer | No | `0` = Failure | `0` | | `data` | object | No | Empty object `{}` on error. | `[object Object]` | | `messages` | array\ | No | Array of error/validation messages. **Error codes:** - `document.not.completed` — `AUDIT_TRAIL` was requested but the document has not been fully completed yet - `document.download.type` — Invalid or unsupported `documentDownloadType` value, including passing multiple values in the same request - `no.document.found` — Document ID not found or you do not have access to it - `no.attachments.exists` — No attachments exist for the given document - `index.out.of.bound` — Index exceeds the number of available files - `index.not.negative` — A negative index value was passed - `invitation.not.found` — Invalid `supportDocumentUrl` (invitee not found) - `validator.invalid` — A required parameter is missing or invalid See **Message** below. | `[object Object]` | #### Message Message object containing a machine-readable code and a human-readable description. Used for success confirmations, errors, and warnings. | Field | Type | Required | Description | Example | |-------|------|----------|-------------|---------| | `code` | string | No | Response message code. | `simpleWorkFlow.success` | | `message` | string | No | Human-readable success or error message. | `Invitations sent successfully.` | ### Sample Response (200) ```json { "status": 0, "data": {}, "messages": [ { "code": "document.not.completed", "message": "Document has not been completed yet. Audit trail cannot be downloaded for incomplete documents." } ] } ```