Skip to main content

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

  1. You need to have Node.js installed on your system.
  2. You'll also need the axios library. You can install it using the following command:
npm install axios
  1. A valid Bearer token (JWT) for authentication.
  2. The transaction ID of the eSignature transaction whose documents you want to download.

Endpoint

GET /transactions/{id}/documents

ParameterTypeLocationRequiredDescription
idstring (UUID)PathYesThe unique identifier of the eSignature transaction.
typestringQueryYesThe type of documents to download.

Document Types

TypeDescription
allAll documents (original + completed). Requires the transaction to be in completed status.
completedOnly the signed/completed documents. Requires the transaction to be in completed status.
originalOnly the original (unsigned) documents. Available regardless of transaction status.

Important: The all and completed document types are only available when the transaction status is completed. Attempting to download these types for an incomplete transaction will return a 400 Bad Request error.

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

StatusReason
400 Bad RequestSession is not complete (when requesting all or completed types)
401 UnauthorizedInvalid or expired Bearer token
404 Not FoundNo transaction found with the provided ID

Steps to Execute the Code Snippet

  1. Create a new file named download_documents.js.
  2. Copy and paste the code snippet provided above into the new file.
  3. Replace <transactionId> and <accessToken> with the appropriate values.
  4. Save the file and open a terminal or command prompt.
  5. Navigate to the folder where you saved the download_documents.js file.
  6. 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.