The process of sending an eSignature envelope using a template has become significantly easier with the ability to include additional documents. Recently, we introduced this new support. In this blog, we will see how to include additional documents while sending an eSignature envelope using a template via an API. We will cover examples in different programming languages, demonstrating how to achieve this with both application/json and multipart/form-data content types.
Why Including Additional Documents Is Important
Including additional documents while sending an eSignature envelope allows users to include all necessary documents in one go, improving efficiency. Whether you need to attach supporting documents, addendums, or additional forms, this feature makes the process seamless.
Prerequisites
- API Key or OAuth Access Token: You need a BoldSign API key, or an access token obtained from an OAuth app. Refer to this documentation for more information about BoldSign API authentication.
- Template ID: The ID of the template you want to use to send an envelope.
- Files: The additional documents you want to attach.
Code Examples
Following are code examples in different programming languages. To send an envelope for signature, you need to construct a payload with all the necessary details. Include details such as the title, message, signer name, and signer email address. If you are using the application/json content type, the files should be updated in base64 format. The base64 format is data:application/{{fileType}};base64,{{content}}. When using the multipart/form-data content type to send an envelope, you should include the files as part of the payload in their original binary format.
Application/JSON
curl -X 'POST' \
'https://api.boldsign.com/v1/template/send?templateId=b8085b47-63b3-47f8-8d5e-cb0acfe2d916' \
-H 'accept: application/json' \
-H 'X-API-KEY: {your API key}' \
-H 'Content-Type: application/json;odata.metadata=minimal;odata.streaming=true' \
-d '{
"title": "Invitation form",
"message": "Kindly review and sign this.",
"roles": [
{
"roleIndex": 1,
"signerName": "Richard",
"signerEmail": "[email protected]"
}
],
"files": [
"data:application/pdf;base64,JVBERi0xLjcKJcfs..."
]
}'
var apiClient = new ApiClient("https://api.boldsign.com", "{your API key}");
var templateClient = new TemplateClient(apiClient);
var documentFilePath = new DocumentFilePath
{
ContentType = "application/pdf",
FilePath = @"{Your file path}",
};
var filesToUpload = new List
{
documentFilePath,
};
var templateRole = new Roles(
roleSignerName:"Richard",
roleSignerEmailAddress:"[email protected]",
locale: Locales.EN);
var roles = new List
{
templateRole,
};
var sendForSignFromTemplate = new SendForSignFromTemplate()
{
TemplateId = "b8085b47-63b3-47f8-8d5e-cb0acfe2d916",
Files = filesToUpload,
};
var documentCreated = templateClient.SendUsingTemplate(sendForSignFromTemplate);
import requests
url = "https://api.boldsign.com/v1/template/send?templateId=b8085b47-63b3-47f8-8d5e-cb0acfe2d916"
payload = {
"title": "Invitation form",
"message": "Kindly review and sign this.",
"roles": [
{
"roleIndex": 1,
"signerName": "Richard",
"signerEmail": "[email protected]"
}
],
"files": [
"data:application/pdf;base64,JVBERi0xLjcKJcfs..."
]
}
headers = {
'accept': 'application/json',
'X-API-KEY': '{your API key}',
'Content-Type': 'application/json;odata.metadata=minimal;odata.streaming=true'
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
const axios = require('axios');
const url = 'https://api.boldsign.com/v1/template/send?templateId=b8085b47-63b3-47f8-8d5e-cb0acfe2d916';
const data = {
title: 'Invitation form',
message: 'Kindly review and sign this.',
roles: [
{
roleIndex: 1,
signerName: 'Richard',
signerEmail: '[email protected]'
}
],
files: [
'data:application/pdf;base64,JVBERi0xLjcKJcfs...'
]
};
const config = {
headers: {
'accept': 'application/json',
'X-API-KEY': '{your API key}',
'Content-Type': 'application/json;odata.metadata=minimal;odata.streaming=true'
}
};
axios.post(url, data, config)
.then(response => console.log(response.data))
.catch(error => console.log(error));
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();
$url = 'https://api.boldsign.com/v1/template/send?templateId=b8085b47-63b3-47f8-8d5e-cb0acfe2d916';
$data = [
'title' => 'Invitation form',
'message' => 'Kindly review and sign this.',
'roles' => [
[
'roleIndex' => 1,
'signerName' => 'Richard',
'signerEmail' => '[email protected]'
]
],
'files' => [
'data:application/pdf;base64,JVBERi0xLjcKJcfs...'
]
];
$response = $client->post($url, [
'headers' => [
'accept' => 'application/json',
'X-API-KEY' => '{your API key}',
'Content-Type' => 'application/json;odata.metadata=minimal;odata.streaming=true'
],
'json' => $data
]);
echo $response->getBody();
?>
Multipart/form-data
curl -X 'POST' \
'https://api.boldsign.com/v1/template/send?templateId=b8085b47-63b3-47f8-8d5e-cb0acfe2d916' \
-H 'accept: application/json' \
-H 'X-API-KEY: {your API key}' \
-F 'files=@{your file path};type=application/pdf' \
-F 'title=Invitation form' \
-F 'message=Kindly review and sign this.' \
-F 'roles[0][roleIndex]=1' \
-F 'roles[0][signerName]=Richard' \
-F 'roles[0][signerEmail][email protected]'
var apiClient = new ApiClient("https://api.boldsign.com", "{your API key}");
var templateClient = new TemplateClient(apiClient);
var documentFilePath = new DocumentFilePath
{
ContentType = "application/pdf",
FilePath = @"{Your file path}",
};
var filesToUpload = new List
{
documentFilePath,
};
var templateRole = new Roles(
roleSignerName:"Richard",
roleSignerEmailAddress:"[email protected]",
locale: Locales.EN);
var roles = new List
{
templateRole,
};
var sendForSignFromTemplate = new SendForSignFromTemplate()
{
TemplateId = "b8085b47-63b3-47f8-8d5e-cb0acfe2d916",
Files = filesToUpload,
};
var documentCreated = templateClient.SendUsingTemplate(sendForSignFromTemplate);
import requests
url = "https://api.boldsign.com/v1/template/send?templateId=b8085b47-63b3-47f8-8d5e-cb0acfe2d916"
files = {
'files': ('{your file name}', open('{your file path}', 'rb'), 'application/pdf')
}
data = {
'title': 'Invitation form',
'message': 'Kindly review and sign this.',
'roles[0][roleIndex]': 1,
'roles[0][signerName]': 'Richard',
'roles[0][signerEmail]': '[email protected]'
}
headers = {
'accept': 'application/json',
'X-API-KEY': '{your API key}'
}
response = requests.post(url, files=files, data=data, headers=headers)
print(response.text)
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const url = 'https://api.boldsign.com/v1/template/send?templateId=b8085b47-63b3-47f8-8d5e-cb0acfe2d916';
const form = new FormData();
form.append('files', fs.createReadStream('{your file path}'), '{your file name}');
form.append('title', 'Invitation form');
form.append('message', 'Kindly review and sign this.');
form.append('roles[0][roleIndex]', 1);
form.append('roles[0][signerName]', 'Richard');
form.append('roles[0][signerEmail]', '[email protected]');
const config = {
headers: {
'accept': 'application/json',
'X-API-KEY': '{your API key}',
...form.getHeaders()
}
};
axios.post(url, form, config)
.then(response => console.log(response.data))
.catch(error => console.log(error));
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
$client = new Client();
$url = 'https://api.boldsign.com/v1/template/send?templateId=b8085b47-63b3-47f8-8d5e-cb0acfe2d916';
$multipart = [
[
'name' => 'files',
'contents' => fopen('{your file path}', 'r'),
'filename' => '{your file name}'
],
[
'name' => 'title',
'contents' => 'Invitation form'
],
[
'name' => 'message',
'contents' => 'Kindly review and sign this.'
],
[
'name' => 'roles[0][roleIndex]',
'contents' => '1'
],
[
'name' => 'roles[0][signerName]',
'contents' => 'Richard'
],
[
'name' => 'roles[0][signerEmail]',
'contents' => '[email protected]'
]
];
$response = $client->post($url, [
'headers' => [
'accept' => 'application/json',
'X-API-KEY' => '{your API key}'
],
'multipart' => $multipart
]);
echo $response->getBody();
?>
Conclusion
By following the examples provided in this blog, you can successfully include additional documents when sending an eSignature envelope using a template via an API. Whether you prefer using the application/json or multipart/form-data content type, the process is straightforward and can be implemented in various programming languages. This added flexibility ensures that your document workflows are efficient, accurate, and tailored to your specific needs.
To experience the benefits firsthand, start a 30-day free trial of BoldSign. We genuinely value your feedback and invite you to share your thoughts below. If you require any assistance or wish to explore our services further, don’t hesitate to schedule a demo or reach out to our dedicated support team via our support portal.
