How to send document using multiple templates by filling existing form fields?

This article provides a step-by-step guide on how to create templates in BoldSign's web app and then use those templates to fill in existing form field values programmatically before sending the document for signature. For example, you may have multiple forms in different templates that you need to send to a signer by pre-filling the values in the form fields programmatically and then sending a signature request.

Follow the steps below to send a document for signature using multiple templates with pre-filled form fields:

  1. Begin by creating templates in BoldSign's web app. If you're unsure how to create templates, you can refer to the guide: How to Create a Template in the BoldSign Web App for detailed instructions.
  2. Once you've created your templates, take note of the unique field IDs associated with each field you've added to the templates. You will need these field IDs in the next steps to programmatically fill in the fields using the BoldSign API.
  3. Please refer to the code examples below, which contain two template IDs (ID of the templates). One template has a field with ID as Name, and the other one has a field with ID as Place. Use the ExistingFormFields property to retrieve all the form fields from both templates and assign values based on the IDs. As a result, the templates will be merged into a single document containing both form fields with updated values and will be sent to the signer.

Code snippet

curl -X 'POST' \ 'https://api.boldsign.com/v1-beta/template/mergeAndSend' \
     -H 'accept: application/json' \
     -H 'X-API-KEY: {your API key}' \
     -H 'Content-Type: application/json;odata.metadata=minimal;odata.streaming=true' \
     -d '{
       "templateIds": [
          "4fe17627-xxxx-41ff-xxxx-0af80fd77740", "d57d9f60-xxxx-4f30-xxxx-2830b6a8fb3f"
        ],
       "title": "Invitation form",
       "message": "Kindly review and sign this.",
       "roles": [
    {
      "roleIndex": 1,
      "signerName": "David",
      "signerEmail": "david@cubeflakes.com",
      "signerType": "Signer",
     "existingFormFields": [
    {
      "id": "Name",
      "value": "David"
    },
    {
      "id": "Place",
      "value": "Washington"
    }
  ],      
      "locale": "EN"
    }
  ] 
  }'
var apiClient = new ApiClient("https://api.boldsign.com", "{Your API key}");
var templateClient = new TemplateClient(apiClient);

var existingFormFieldCollections = new List<ExistingFormField>
{
    new ExistingFormField(
        id: "State",
        value: "North Carolina"
    ),
    new ExistingFormField(
        id: "Country",
        value: "United States"
    ),
};

var templateRole = new Roles(
    roleSignerIndex:1,
    roleSignerName:"David",
    roleSignerEmailAddress:"david@cubeflakes.com",
    existingFormFields: existingFormFieldCollections,
    locale: Locales.EN);

var roles = new List<Roles>
{
    templateRole,
};

var mergeAdSend = new MergeAndSendForSign()
{
    TemplateIds = new string[] { "4fe17627-xxxx-41ff-xxxx-0af80fd77740", "d57d9f60-xxxx-4f30-xxxx-2830b6a8fb3f" },
    Roles = roles
};

var documentCreated = await templateClient.MergeAndSendAsync(mergeAdSend).ConfigureAwait(false);
import requests

url = "https://api.boldsign.com/v1-beta/template/mergeAndSend"

payload = {
    "templateIds": ["4fe17627-xxxx-41ff-xxxx-0af80fd77740", "d57d9f60-xxxx-4f30-xxxx-2830b6a8fb3f"],
    "roles": [
        {
            "roleIndex": 1,
            "signerName": "David",
            "signerEmail": "david@cubeflakes.com",
            "existingFormFields": [
                {
                    "id": "State",
                    "value": "North Carolina"
                },
                {
                    "id": "Country",
                    "value": "United States"
                }
            ]
        }
    ]
}

headers = {
    'accept': 'application/json',
    'X-API-KEY': '{Your API key}',
    'Content-Type': 'application/json;odata.metadata=minimal;odata.streaming=true'
}

response = requests.post(url, headers=headers, json=payload)
print(response.text)
const axios = require('axios');
const response = axios.post(
    'https://api.boldsign.com/v1-beta/template/mergeAndSend',
    {
        'templateIds': ['4fe17627-xxxx-41ff-xxxx-0af80fd77740', 'd57d9f60-xxxx-4f30-xxxx-2830b6a8fb3f'],
        'roles': [
            {
                'roleIndex': 1,
                'signerName': 'David',
                'signerEmail': 'david@cubeflakes.com',
                'existingFormFields': [
                    {
                        'id': "State",
                        'value': "North Carolina"
                    },
                    {
                        'id': "Country",
                        'value': "United States"
                    }
                ]
            }
        ]
    },
    {
        headers: {
            'accept': 'application/json',
            'X-API-KEY': '{Your API key}',
            'Content-Type': 'application/json;odata.metadata=minimal;odata.streaming=true'
        }
    }
);

In the provided code examples, make sure to replace the templateIds with the actual IDs of the templates you created. Also, update the signerEmail and signerName properties with the email and name of the signer you wish to send the document to. Lastly, use the field IDs you noted earlier to pre-fill the fields with the desired values and include these field IDs and values in the existingFormFields array.

By following these steps and using the code snippets provided, you can send documents using multiple templates with pre-filled form fields through BoldSign.