Category / Section
How to create a Template using BoldSign API?
Published:
7 mins read
If you frequently need to send the same contracts to different people for signing, templates can help you save time. Once you create a template, you can send contracts in less than a minute using the template.
Below are examples of how to create a template in various programming languages:
Code snippet
cURL
curl -X 'POST' \ 'https://api.boldsign.com/v1/template/create' \
-H 'accept: application/json' \
-H 'X-API-KEY: {your API key}' \
-H 'Content-Type: multipart/form-data' \
-F 'DocumentMessage=document message for signers' \
-F 'Files=@{your file};type=application/pdf' \
-F 'Title=title of the template' \
-F 'AllowMessageEditing=true' \
-F 'Description=testingDescription' \
-F 'DocumentTitle=title of the document' \
-F 'Roles={
"name": "Manager",
"index": 1,
"defaultSignerName": "Alex Gayle",
"defaultSignerEmail": "alexgayle@cubeflakes.com",
"signerOrder": 1,
"signerType": "Signer",
"formFields": [
{
"id": "sign_id",
"fieldType": "Signature",
"pageNumber": 1,
"bounds": {
"x": 50,
"y": 100,
"width": 100,
"height": 60
},
"isRequired": true
}
]
}'
C#
var apiClient = new ApiClient("https://api.boldsign.com", "API-KEY");
var templateClient = new TemplateClient(apiClient);
var documentFilePath = new DocumentFilePath
{
ContentType = "application/pdf",
FilePath = "{file path}",
};
var filesToUpload = new List<IDocumentFile>
{
documentFilePath,
};
var signatureField = new FormField(
id: "sign_id",
type: Type.Signature,
pageNumber: 1,
bounds: new Rectangle(x: 50, y: 50, width: 200, height: 30));
var formFieldsCollections = new List<FormField>
{
signatureField,
};
var templateRole = new TemplateRole(
roleIndex: 1,
name: "Manager",
defaultSignerName: "Alex Gayle",
defaultSignerEmail: "alexgayle@cubeflakes.com",
signerOrder: 1,
signerType: SignerType.Signer,
formFields: formFieldsCollections,
locale: Locales.EN);
var roles = new List<TemplateRole>
{
templateRole,
};
var templateRequest = new CreateTemplateRequest()
{
Title = "title of the template",
DocumentMessage = "document message for signers",
Files = filesToUpload,
Description = "testingDescription",
DocumentTitle = "title of the document",
Roles = roles
};
var templateCreated = templateClient.CreateTemplate(templateRequest);
Python
import boldsign
configuration = boldsign.Configuration(
api_key = "YOUR_API_KEY"
)
with boldsign.ApiClient(configuration) as api_client:
template_api = boldsign.TemplateApi(api_client)
form_fields = [
boldsign.FormField(
id = "sign_id",
name = "sign",
fieldType="Signature",
page_number=1,
font="Helvetica",
bounds=boldsign.Rectangle(
x=50,
y=100,
width=100,
height=60
),
is_required=True
)
]
role = [
boldsign.TemplateRole(
index=1,
name="Hr",
defaultSignerName="Alex Gayle",
defaultSignerEmail="alexgayle@boldsign.dev",
signerOrder=1,
signerType="Signer",
locale="EN",
imposeAuthentication="None",
deliveryMode="Email",
formFields=form_fields,
allowRoleEdit=True,
allowRoleDelete=True
)
]
create_template_request = boldsign.CreateTemplateRequest(
enableReassign=True,
allowNewRoles=True,
enablePrintAndAssign=False,
documentMessage="document message for signers",
enableSigningOrder=False,
useTextTags=False,
title="title of the template",
allowMessageEditing=True,
description="testingDescription",
documentTitle= "title of the document",
allowNewFiles=True,
roles=role,
files=["YOUR_FILE_PATH"]
)
create_template_response = template_api.create_template(create_template_request=create_template_request)
NodeJS
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const form = new FormData();
form.append('AllowNewRoles', 'true');
form.append('DocumentMessage', 'document message for signers');
formData.append('Files', fs.createReadStream(filePath), {
filename: 'yourfilename.pdf',
contentType: 'application/pdf'
});
form.append('Title', 'title of the template');
form.append('AllowMessageEditing', 'true');
form.append('Description', 'testingDescription');
form.append('DocumentTitle', 'title of the document');
form.append('Roles', '{\n "name": "Manager",\n "index": 1,\n "defaultSignerName": "Alex Gayle",\n "defaultSignerEmail": "alexgayle@cubeflakes.com",\n "signerOrder": 1,\n "signerType": "Signer",\n "locale": "EN",\n "imposeAuthentication": "None",\n "deliveryMode": "Email",\n "formFields": [\n {\n "id": "sign_id",\n "name": "sign",\n "fieldType": "Signature",\n "pageNumber": 1,\n "bounds": {\n "x": 50,\n "y": 100,\n "width": 100,\n "height": 60\n },\n "isRequired": true\n }\n ],\n "allowRoleEdit": true,\n "allowRoleDelete": true\n}');
const response = await axios.post(
' https://api.boldsign.com/v1/template/create',
form,
{
headers: {
...form.getHeaders(),
'accept': 'application/json',
'X-API-KEY': '{API-KEY}',
'Content-Type': 'multipart/form-data'
}
}
);
PHP
<?php
require_once "vendor/autoload.php";
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$client = new GuzzleHttp\Client([ 'verify' => false, ]);
$headers = [
'accept' => 'application/json',
'X-API-KEY' => '{your API key}'
];
$options = [
'multipart' => [
[
'name' => 'DocumentMessage',
'contents' => 'document message for signers'
],
[
'name' => 'Files',
'contents' => Utils::tryFopen('/path/to/file', 'r'),
'filename' => '/path/to/file',
'headers' => [
'Content-Type' => '<Content-type header>'
]
],
[
'name' => 'Title',
'contents' => 'title of the template'
],
[
'name' => 'AllowMessageEditing',
'contents' => 'true'
],
[
'name' => 'Description',
'contents' => 'testingDescription'
],
[
'name' => 'DocumentTitle',
'contents' => 'title of the document'
],
[
'name' => 'Roles',
'contents' => '{
"name": "Manager",
"index": 1,
"defaultSignerName": "Alex Gayle",
"defaultSignerEmail": "alexgayle@cubeflakes.com",
"signerOrder": 1,
"signerType": "Signer",
"formFields": [
{
"id": "sign_id",
"fieldType": "Signature",
"pageNumber": 1,
"bounds": {
"x": 50,
"y": 100,
"width": 100,
"height": 60
},
"isRequired": true
}
]
}'
]
]];
$request = new Request('POST', 'https://api.boldsign.com/v1/template/create', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();
In the provided code example, provide values for Roleindex
, Rolename
. Replace the values for API KEY
with the correct value, File
with your correct file path. When the above codes are executed, a template is created successfully with the values provided and templateId
is returned.