> ## Documentation Index
> Fetch the complete documentation index at: https://agents.nanonets.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# docusign_get_envelope_document

> Download a signed PDF from a DocuSign envelope and store it as a file the next tool can consume.

Downloads a document from a DocuSign envelope, stores it, and returns a `file_url`. The typical use is filing a completed intake form into an EHR: this tool produces the PDF, and an EHR upload tool consumes the `file_url` it returns — on this platform that is `advancedmd_op_ehr_upload_document`, which ships separately from this tool.

Read-only against DocuSign. Nothing is sent, voided or modified.

See [DocuSign integration](/docs/tools/docusign) for authentication and setup.

## Inputs

| Field         | Required | Description                                                                                                                                               |
| ------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `envelope_id` | yes      | Envelope to download from, as returned by `docusign_send_envelope`                                                                                        |
| `document_id` | no       | Which document. Defaults to `1`, the signed form. `combined` merges every document in the envelope into one PDF. A numeric id selects a specific document |
| `file_name`   | no       | Name for the stored file. Defaults to the document's name in DocuSign, falling back to `envelope-<id>-document-<document_id>.pdf`                         |

## Outputs

| Field                 | Description                                                                       |
| --------------------- | --------------------------------------------------------------------------------- |
| `file_url`            | Pass this to whichever tool files the document                                    |
| `file_id`             | Platform file id                                                                  |
| `file_name`           | Name the file was stored under                                                    |
| `size_bytes`          | Size of the downloaded PDF                                                        |
| `document_id`         | The document actually downloaded                                                  |
| `available_documents` | Every document on the envelope, with id, name, type, signing order and page count |

`available_documents` is returned on the same call as the download, so you do not need a separate listing step to discover what else the envelope holds. It is omitted if the listing call fails — the download is still attempted and reported.

## Picking a document id

Only two ids are predictable: `1` is always the first document (the signed form), and `combined` is always the whole envelope merged. Everything else depends on how the template was built, so read `available_documents` rather than guessing.

For a single-document intake packet, the default is what you want. For a multi-document envelope where the whole signed set should be filed as one attachment, use `combined`.

## Check the envelope is completed first

Only an envelope with status `completed` contains signed content. Downloading from a `sent` or `delivered` envelope returns the unsigned form, which is rarely what you want and is easy to file into a chart by mistake. Call `docusign_get_envelope` and check `is_completed` before downloading.

## Limits

* **25 MB per document.** Larger documents are refused rather than truncated — a clipped PDF filed into a patient record is worse than a failed step. Download oversized documents directly from DocuSign.
* A document that arrives empty is reported as an error, not stored as a zero-byte file.

## Expected errors

| Situation                              | Behaviour                                                                          |
| -------------------------------------- | ---------------------------------------------------------------------------------- |
| Envelope or document id does not exist | Error naming the envelope and document                                             |
| Envelope not yet completed             | Succeeds, but the PDF is the unsigned form — check status first                    |
| Document over 25 MB                    | Error telling you to download it from DocuSign directly                            |
| Access token rejected                  | Error surfaces the HTTP 401; the cached token is dropped so the next call re-mints |
| File storage unavailable               | Error before any download is attempted                                             |

## Storage and PHI

The document is written through the platform's audited storage path, which emits the HIPAA S3 audit event and enforces the platform size ceiling. Signed intake forms routinely carry PHI, so this tool never bypasses that seam.

If the file record cannot be created after upload, the stored object is deleted rather than left orphaned, and a failure to clean up is logged.
