How to create a Template using BoldSign API?
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 -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 } ] }'
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);
import requests import json url = "https://api.boldsign.com/v1/template/create" payload = { "AllowNewRoles": "true", "DocumentMessage": "document message for signers", "Title": "title of the template", "AllowMessageEditing": "true", "Description": "testingDescription", "DocumentTitle": "title of the document", "Roles": json.dumps( { "name": "Manager", "index": 1, "defaultSignerName": "Alex Gayle", "defaultSignerEmail": "alexgayle@boldsign.dev", "signerOrder": 1, "signerType": "Signer", "locale": "EN", "imposeAuthentication": "None", "deliveryMode": "Email", "formFields": [ { "id": "sign_id", "name": "sign", "fieldType": "Signature", "pageNumber": 1, "bounds": {"x": 50, "y": 100, "width": 100, "height": 60}, "isRequired": True } ], "allowRoleEdit": True, "allowRoleDelete": True, } ), } files = [ ("Files", ("file", open("{your file}", "rb"), "application/msword")) ] headers = { "accept": "application/json", "X-API-KEY": "{your api ky}", } response = requests.request("POST", url, headers=headers, data=payload, files=files) print(response.text)
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 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.