The BoldSign mobile app is now available. Visitthis link for more details and give it a try!

The BoldSign mobile app is now available. Visitthis link for more details and give it a try!

Request Demo
BoldSign Logo Small

Features

Explore the BoldSign features that make eSigning easier.

How to Create a Template in BoldSign via API Banner Image

How to Create a Template via API

Document workflow management can often be time-consuming, especially when repetitive tasks are involved. In this blog post, we will explore how to streamline document creation and distribution using the BoldSign API. Specifically, we’ll delve into the process of creating templates via API, enabling you to save time and enhance efficiency in managing contracts and agreements.

Why Templates Matter

Imagine needing to send the same contracts to different groups of individuals regularly. Creating templates allows you to reduce the time and effort required significantly. With the BoldSign API, you can easily generate templates for various purposes, whether it’s for self-signing or sending signature requests to multiple signers.

Asynchronous Template Processing

One aspect to understand about template creation is that it’s an asynchronous process. Although you’ll receive a template ID promptly upon initiation, the actual file creation may still be underway in the background. To confirm whether the template has been successfully created, you’ll need to listen for webhooks.

Upon completion, the system triggers either a TemplateCreated or TemplateCreateFailed event, indicating success or failure, respectively. If the creation fails, an error message will be provided. Resolving any errors promptly ensures seamless template creation in subsequent requests.

Read more about webhooks

Code Snippets

Let’s explore code snippets in various programming languages to demonstrate how to create templates via the BoldSign API.

Curl

    
curl -X 'POST' \ 'https://api.boldsign.com/v1/template/create' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: {API key}' \
  -H 'Content-Type: multipart/form-data' \
  -F 'DocumentMessage=document message for signers' \
  -F 'Files=@{Your File Path};type=application/pdf' \
  -F 'Title=Title of the template' \
  -F 'DocumentTitle=Title of the document' \
  -F 'Roles={
  "name": "Hr",
  "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 = @"{Your File Path}",
};

var filesToUpload = new List
{
    documentFilePath,
};

var signatureField = new FormField(
    id: "sign_id",
    type: FieldType.Signature,
    pageNumber: 1,
    bounds: new Rectangle(x: 50, y: 50, width: 200, height: 30));

var formFieldsCollections = new List
{
    signatureField,
};

var templateRole = new TemplateRole(
    roleIndex: 1,
    name: "Hr",
    defaultSignerName: "Alex Gayle",
    defaultSignerEmail: "alexgayle@cubeflakes.com",
    signerOrder: 1,
    signerType: SignerType.Signer,
    formFields: formFieldsCollections,
    locale: Locales.EN);

var roles = new List
{
    templateRole,
};

var templateRequest = new CreateTemplateRequest()
{
    Title = "Title of the template",
    DocumentMessage = "Document message for signers",
    Files = filesToUpload,
    DocumentTitle = "Title of the document",
    Roles = roles
};

var templateCreated = templateClient.CreateTemplate(templateRequest);
 

Python

    
import requests
import json
url = "https://api.boldsign.com/v1/template/create"
payload = {
    "Title": "Title of the template",
    "DocumentTitle": "Title of the document",
    "Roles": json.dumps(
        {
            "name": "Hr",
            "index": 1,
            "defaultSignerName": "Alex Gayle",
            "defaultSignerEmail": "alexgayle@boldsign.dev",
            "signerOrder": 1,
            "signerType": "Signer",
            "locale": "EN",
            "formFields": [
                {
                    "id": "sign_id",
                    "name": "sign",
                    "fieldType": "Signature",
                    "pageNumber": 1,
                    "bounds": {"x": 50, "y": 100, "width": 100, "height": 60},
                    "isRequired": True,
                }
            ],
        }
    ),
}
files = [
    ("Files", ("file", open("{Your File Path}", "rb"), "application/pdf"))
]
headers = {
    "accept": "application/json",
    "X-API-KEY": "{API key}
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
 

Node JS

    
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const form = new FormData();
form.append('Files', fs.readFileSync('{Your File Path};type=application/pdf'), 'Bill-of-Sale.pdf;type=application/pdf');
form.append('Title', 'Title of the template');
form.append('AllowMessageEditing', 'true');
form.append('DocumentTitle', 'Title of the document');
form.append('Roles', '{\n  "name": "Hr",\n  "index": 1,\n  "defaultSignerName": "Alex Gayle",\n  "defaultSignerEmail": "alexgayle@cubeflakes.com",\n  "signerOrder": 1,\n  "signerType": "Signer",\n  "locale": "En",\n  "deliveryMode": "Email",\n  "imposeAuthentication": "None",\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;
use \GuzzleHttp\Psr7\Utils;

$client = new Client();
$headers = [
  'accept' => 'application/json',
  'X-API-KEY' => '{your API key}'
];
$options = [
  'multipart' => [
    [
      'name' => 'Files',
      'contents' => Utils::tryFopen('{Your File Path}, 'r'),
      'filename' => 'Your File Name,
      'headers'  => [
        'Content-Type' => ''
      ]
    ],
    [
      'name' => 'Title',
      'contents' => 'title of the template'
    ],
    [
      'name' => 'DocumentTitle',
      'contents' => 'title of the document'
    ],
    [
      'name' => 'Roles',
      'contents' => '{
  "name": "Hr",
  "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();
 

Conclusion

In conclusion, using the BoldSign API to create templates is a great way to streamline document workflows. In handling contracts and agreements, you can save time by just tweaking already-perfected documents. If you’re integrating BoldSign into your application, creating templates via the API is a valuable process to know.

Picture of Gopinath Kannusamy

Gopinath Kannusamy

Gopinath is a passionate software developer with 2 years of experience at BoldSign. He is an avid writer and enjoys sharing his insights on technology and development. In his free time, he enjoys exploring new technologies and learning new things.

Share this blog

Picture of Gopinath Kannusamy

Gopinath Kannusamy

Gopinath is a passionate software developer with 2 years of experience at BoldSign. He is an avid writer and enjoys sharing his insights on technology and development. In his free time, he enjoys exploring new technologies and learning new things.

Subscribe RSS feed

Leave a Reply

Your email address will not be published. Required fields are marked *