How to download the attachments in document using BoldSign API?

In BoldSign, the signer can attach a file while signing a document. For that the sender must have added a attachment field in the document, before sending it. This article is about downloading the attached file by using the downloadAttachment API.

Follow these steps to successfully download the attachment that the signer has attached:

Get the attachment ID from the document properties

To download the attachment, you'll need the attachmentId of the attachment present in the document that was sent for signature and the documentId of the document. You will receive the documentId after sending a document via API. You can obtain the attachmentId from the document properties, which can be retrieved using the properties API. You can refer to the following link to get the document properties: Get Document Properties.

Look for the id value inside the formField object where the fieldType is specified as Attachment. This id corresponds to the attachmentId you need.

Example response from properties API containing attachment form field

{
    "formFields": [
        {
          "id": "attachment_ppYla",
          "type": "attachment",
          "value": "Consent form - Attached",
          "font": "Helvetica",
          "isRequired": true,
          "isReadOnly": false,
          "lineHeight": 14,
          "fontSize": 13,
          "fontColor": "#000000",
          "isUnderline": false,
          "isItalic": false,
          "isBold": false,
          "groupName": "",
          "placeholder": "",
          "validationtype": "None",
          "validationCustomRegex": "",
          "validationCustomRegexMessage": "",
          "dateFormat": "",
          "imageInfo": null,
          "attachmentInfo": {
            "title": "Consent form",
            "description": "",
            "allowedFileTypes": "PDF, DOCUMENT, IMAGE",
            "acceptedFileTypes": [
              "PDF",
              "DOCUMENT",
              "IMAGE"
            ]
          },
          "fileInfo": {
            "fileName": "Consent Form",
            "fileSize": 18028,
            "contentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "extension": "docx"
          },
          "editableDateFieldSettings": null,
          "hyperlinkText": "",
          "conditionalRules": [],
          "bounds": {
            "x": 305.00345,
            "y": 38.004627,
            "width": 173.10417,
            "height": 28
          },
          "pageNumber": 1,
          "dataSyncTag": "",
          "dropdownOptions": [],
          "textAlign": "Left",
          "textDirection": "LTR",
          "characterSpacing": 0
        }
    ]
}

Download the attachment using the API

To download the attachment, you'll use the documentId and attachmentId as query parameters in the following endpoint: v1/document/downloadAttachment.

Here are example code snippets in different programming languages that demonstrate how to perform the download:

Code snippet

curl -X GET 'https://api.boldsign.com/v1/document/downloadAttachment?documentId={Your document Id}&attachmentId={Your attachment Id}' \
-H 'accept: application/json' \
-H 'X-API-KEY: {your-api-key}'

var apiClient = new ApiClient("https://api.boldsign.com", "Your API-KEY");
var documentClient = new DocumentClient(apiClient);
var documentStream = documentClient.DownloadAttachment("{Your document Id}", "{Your attachment Id}");

import requests

url = "https://api.boldsign.com/v1/document/downloadAttachment?documentId={Your document Id}&attachmentId={Your attachment Id}"

payload={}
headers = {
  'accept': 'application/json',
  'X-API-KEY': '{your API key}'
}

response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
const axios = require('axios');
const response = axios.get('https://api.boldsign.com/v1/document/downloadAttachment', {
    params: {
        'documentId': '{Your document Id}',
        'attachmentId': '{Your attachment Id}'
    },
    responseType: "stream",
    headers: {
        'accept': 'application/json',
        'X-API-KEY': '{your API key}'
    }
});

In the provided examples, make sure to replace {Your document Id} with the actual ID of the document and {Your attachment Id} with the actual ID of the attachment that you intend to download, which you obtained from the properties API.

After executing the code, the document will be generated, and you'll be able to proceed with downloading it.