How to prefill values for image field while sending document from template for signature?

BoldSign allows you to prefill values for existing form fields when sending documents from a template. This article provides a guide on how to prefill values for image fields.

Templates are pre-designed layouts that streamline the creation of new documents. They offer a consistent structure and format, saving time, especially when sending the same contracts to multiple recipients. For more information, please refer to the Create Template article.

Once you got a template ID, you can prefill the values for existing form fields and send document from the template.To prefill values for existing form fields in a template, you need to use the Properties API to retrieve the form field IDs and assign values to these fields. For more details, read about the Template Properties API.

Once you have the IDs for the image field, you can assign the image form field ID to the existingFormFields ID and assign the value which image field you want to prefill the value. You can provide the image field in base64 format like data:application/{{fileType}};base64,{{content}}.

Here is an example demonstrating how to prefill image field values when sending a document from a template:

Code snippet

curl -X 'POST' \ 'https://api.boldsign.com/v1/template/send?templateId=908625d5-xxxx-xxxx-8849-54e31ee7a6ed' \
     -H 'accept: application/json' \
     -H 'X-API-KEY: {Your API Key}' \
     -H 'Content-Type: application/json;odata.metadata=minimal;odata.streaming=true' \
     -d '{
       "title": "Sample document",
       "message": "Kindly review and sign this.",
       "roles": [
    {
      "roleIndex": 1,
      "signerName": "Richard",
      "signerEmail": "richards@cuberflakes.com",
      "signerType": "Signer",
      "signerRole": "Manager",
      "existingFormFields": [
          {
             "id": "Image1", 
            "value":"data:image/png;base64,iVBORw0KGgoAAAANS..."
           },
                  
         ],    

    "locale": "EN"
    }
  ],
    
 }'


using BoldSign.Api;
using BoldSign.Model;
var apiClient = new ApiClient("https://api.boldsign.com", "{Your API Key}");
var templateClient = new TemplateClient(apiClient);

var existingFormFieldCollections = new List<ExistingFormField>
{
    new ExistingFormField(
        id: "Image1",
        value: "data:image/png;base64,iVBORw0K..."
    )
   
};
var templateRole = new Roles(
    roleSignerName:"Richard",
    roleSignerEmailAddress:"richards@cuberflakes.com",
    roleSignerIndex:1,
    existingFormFields:existingFormFieldCollections,
    locale: Locales.EN);

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

var sendForSignFromTemplate = new SendForSignFromTemplate()
{
    TemplateId = "908625d5-xxxx-xxxx-8849-54e31ee7a6ed",
    Roles = roles,
    
};

var documentCreated =  templateClient.SendUsingTemplate(sendForSignFromTemplate);

Console.WriteLine(documentCreated.DocumentId);


import requests
import json

url = "https://api.boldsign.com/v1/template/send?templateId=d6bad813-xxxx-xxxx-8c9e-e91a96c06392"

payload = {
    "message": "Kindly review and sign this.",
    "roles": [
        {
            "roleIndex": 1,
            "signerName": "Richard",
            "signerEmail": "richards@cuberflakes.com",
            "existingFormFields": [
                {
                    "id": "Image1",
                    "value": "data:image/jpeg;base64,9j4AAQSkZJ.."
                }
            ]
        }
    ]
}

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, data=json.dumps(payload))

print(response.text)


const axios = require('axios');

async function GetData(){
try{
 
const response = await axios.post(
    'https://api.boldsign.com/v1/template/send',
    {
        'roles': [
            {
                'roleIndex': 1,
                'signerName': 'Richard',
                'signerEmail': 'richards@cuberflakes.com',
                'existingFormFields': [
                    {
                        'id': 'Image1',
                        'value': 'data:image/jpeg;base64,9j4AAQSk...'
                    }
                ]
                
          },
           
        ],
      
        title: "Simple document",
	    message: "Kindly review and sign this.",
    },
    {

        params: {
            'templateId': 'd6bad813-xxxx-xxxx-8c9e-e91a96c06392',
        },
        headers: {
            'accept': 'application/json',
            'X-API-KEY': '{Your API Key}',
            'Content-Type': 'application/json;odata.metadata=minimal;odata.streaming=true'
        }
    }

);
  console.log(JSON.stringify(response.data));
  return response;
  }
  catch (error) {
    console.error('Error:', error.message);
    throw error; 
  } 
}
  GetData();

In the provided code examples, make sure to replace the templateId with the actual ID of the template you created. Also, update the SignerEmail and SignerName properties with the email and name of the signer you wish to send the document. Once the above code is executed, the image form field will be successfully prefilled with the provided image.