Download Transaction Documents
This guide walks you through downloading documents from an eSignature transaction as a ZIP file using the Stewart Sign API.
When to Use
Downloading transaction documents is useful when you need to:
- Retrieve completed (signed) documents after all participants have signed
- Download original (unsigned) documents for reference
- Archive all documents associated with a transaction
Requirements
- You need to have Node.js installed on your system.
- You'll also need the axios library. You can install it using the following command:
npm install axios
- A valid Bearer token (JWT) for authentication.
- The transaction ID of the eSignature transaction whose documents you want to download.
Endpoint
GET /transactions/{id}/documents
| Parameter | Type | Location | Required | Description |
|---|---|---|---|---|
id | string (UUID) | Path | Yes | The unique identifier of the eSignature transaction. |
type | string | Query | Yes | The type of documents to download. |
Document Types
| Type | Description |
|---|---|
all | All documents (original + completed). Requires the transaction to be in completed status. |
completed | Only the signed/completed documents. Requires the transaction to be in completed status. |
original | Only the original (unsigned) documents. Available regardless of transaction status. |
Important: The
allandcompleteddocument types are only available when the transaction status iscompleted. Attempting to download these types for an incomplete transaction will return a400 Bad Requesterror.
Code Snippet
Use the following code snippet to download transaction documents. Replace <transactionId> with the actual transaction ID, and <accessToken> with your API access token.
const axios = require("axios");
const fs = require("fs");
const transactionId = "<transactionId>";
const documentType = "completed"; // "all", "completed", or "original"
const config = {
method: "get",
url: `https://public-api.sign.stewart.com/transactions/${transactionId}/documents`,
params: {
type: documentType,
},
headers: {
Authorization: "Bearer <accessToken>",
},
responseType: "arraybuffer", // Important: receive binary data
};
axios(config)
.then(function (response) {
const filename = `${documentType}-documents.zip`;
fs.writeFileSync(filename, response.data);
console.log(`Documents downloaded successfully: ${filename}`);
})
.catch(function (error) {
console.log(error.response?.data?.toString() || error.message);
});
Successful Response
On success, the API returns a ZIP file containing the requested documents. The response headers include:
Content-Type: application/zip
Content-Disposition: attachment; filename=completed-documents.zip
Error Responses
| Status | Reason |
|---|---|
400 Bad Request | Session is not complete (when requesting all or completed types) |
401 Unauthorized | Invalid or expired Bearer token |
404 Not Found | No transaction found with the provided ID |
Steps to Execute the Code Snippet
- Create a new file named
download_documents.js. - Copy and paste the code snippet provided above into the new file.
- Replace
<transactionId>and<accessToken>with the appropriate values. - Save the file and open a terminal or command prompt.
- Navigate to the folder where you saved the
download_documents.jsfile. - Run the following command to execute the script:
node download_documents.js
If the request is successful, a ZIP file will be saved in the current directory. In case of an error, the error details will be displayed instead.
Additional Resources
For more information about the eSignature API, visit the API reference.
If you need further assistance or have questions, feel free to reach out to our support team.