Articles in this section

Automate eSignature Requests in Apps Script using BoldSign API

Published:

This guide provides a step-by-step approach to automating document workflows using Google Forms, Google Sheets, Google Docs templates, and BoldSign for electronic signatures. Upon submission of a Google Form, the system dynamically generates a document from a predefined Google Docs template, populates it with data from the associated Google Sheet, converts it into a PDF, and seamlessly sends it to BoldSign for eSignature.

Follow the Step-by-Step Instructions:

Step 1: Create a Google Docs Template

  1. Go to https://docs.google.com and create a new document.
  2. Add placeholders as per your requirement, for example like {{Name}} and {{Email}} etc., where you want the data to appear.
  3. Save the document and copy the document ID from the URL.

Step 2: Create a Google Form

  1. Go to https://forms.google.com and create a new form.
    image.png
  2. Add fields based on your requirements, for example Name, Email
    image.png
  3. Link the form to a Google Sheet to store responses.
    image.png

image.png

Step 3: Prepare the Apps Script

  1. Open the linked Google Sheet.
  2. Go to Extensions > Apps Script.
    image.png

Code Snippet:

function onFormSubmit(e) {
 const apiKey = 'YOUR_BOLDSIGN_API_KEY ';
 const templateId = 'YOUR_GOOGLE_DOC_TEMPLATE_ID '; 

 const name = e.values[1];  // Name field
 const email = e.values[2]; // Email field

 // Step 1: Copy the template
 const copiedDoc = DriveApp.getFileById(templateId).makeCopy(`Agreement for ${name}`);
 const docId = copiedDoc.getId();
 const doc = DocumentApp.openById(docId);
 const body = doc.getBody();

 // Step 2: Replace placeholders
 body.replaceText('{{Name}}', name);
 body.replaceText('{{Email}}', email);
 doc.saveAndClose();

 // Step 3: Export as PDF
 const pdf = DriveApp.getFileById(docId).getAs('application/pdf');
 const base64File = Utilities.base64Encode(pdf.getBytes());
 const base64WithType = `data:${pdf.getContentType()};base64,${base64File}`;

 // Step 4: Send to BoldSign
 const payload = {
   title: 'Employment Agreement',
   message: 'Enter a message.',
   files: [
     {
       fileName: pdf.getName(),
       base64: base64WithType
     }
   ],
   signers: [
     {   
       name: name,
       emailAddress: email,
       formFields: [ 
         {
           id: 'Sig1',
           fieldType: "Signature",
           isRequired: true,
           pageNumber: 1,
           bounds: {
             x: 100,
             y: 300,
             width: 200,
             height: 30
           }
         },
       ]
     }
   ],

 };

 const options = {
   method: 'post',
   contentType: 'application/json',
   headers: {
     'X-API-KEY': apiKey
   },
   payload: JSON.stringify(payload),
   muteHttpExceptions: true
 };

 try {
   const response = UrlFetchApp.fetch('https://api.boldsign.com/v1/document/send', options);
   Logger.log('Response Code: ' + response.getResponseCode());
   Logger.log('Response Body: ' + response.getContentText());
 } catch (error) {
   Logger.log('Error: ' + error.message);
 }
} 

Step 4: Set Up the Trigger

  1. In Apps Script, go to the Triggers tab.
    image.png
  2. Click “+ Add Trigger”.
    image.png
  3. Choose the function: “onFormSubmit”
  4. Event source: “From spreadsheet”
  5. Event type: “On form submit”

Untitled_picture.png

  1. Save the changes.

Step 5: Test the Workflow

  1. Submit a test entry via Google Form.
  2. A personalized PDF document will be generated and automatically sent to BoldSign for signature.
Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Access denied
Access denied