By integrating eSignatures into your Node.js application, you can easily carry out the entire electronic signature process within your app. This empowers you and your users to perform all eSignature functionalities, including sending signature requests, signing documents, tracking document statuses, and downloading signed documents. You will streamline the eSignature workflow and eliminate the need for third-party applications, enhancing efficiency and productivity.
In this blog post, we’ll guide you through the process of integrating eSignatures into your Node.js application using BoldSign, an advanced eSignature solution. With a comprehensive suite of APIs, BoldSign makes it easy to integrate electronic signing capabilities into your existing applications.
To demonstrate the benefits of integrating eSignatures, let’s take a real-life situation where you are a software developer working for a real estate agency. Your agency deals with numerous contracts and agreements that require signatures from agents, buyers, sellers, and other parties involved. Managing the signing process manually can be time-consuming, error-prone, and reduce the agency’s efficiency. However, with an eSignature application built with Node.js and BoldSign, you can reduce these downsides.
Getting started
To begin integrating eSignatures into your Node.js application using the BoldSign APIs, you’ll need the following prerequisites:
- Node.js: Ensure that Node.js is installed on your machine.
- BoldSign account: This can either be a paid account or a free sandbox account. If you don’t have one, you can sign up for a free sandbox account.
- BoldSign API key: You will need an API key to authenticate your access. You can generate one on the API Key – BoldSign page.
Setting up the Node.js project
If you wish to integrate eSignatures into your existing application, you can skip this step and move to Integrating the BoldSign API section. Otherwise, begin by creating a new directory for your project and initializing a new Node.js project.
npm install express dotenv
- Express: A web application framework for Node.js.
- Dotenv: A module for loading environment variables from a .env file.
Installing the BoldSign Node SDK
To integrate BoldSign eSignatures into your express application, install the official BoldSign Node SDK:
npm install boldsign
You can install the BoldSign Node SDK using the official Node package available on boldsign – npm
You can also refer to the Official BoldSign Node SDK Documentation, which provides detailed guidance on installation, configuration, and usage in Node.js applications.
These dependencies will enable you to create a server, handle API requests, and load environment variables effectively.
Integrating the BoldSign API
To configure your environment variables, create a .env file in your project directory if you haven’t already done so. Open the file and include your BoldSign API key that you generated previously. This ensures secure communication between your Node.js application and the BoldSign API.
BOLDSIGN_API_KEY=<Your API Key>
Integrating the eSignatures into your Node.js application
Now that you have set up the Node.js project, we can integrate the eSignature functionalities into the application using BoldSign APIs.
To expedite the document-creation process for the real estate agency’s contracts, you can utilize a preconfigured template. You have the option to create the templates using either BoldSign for web or the BoldSign API.
Ensure that the templates you create include all the necessary information and fields required to complete your contracts or agreements. By including all the essential details in the templates, you can simplify the document preparation process and facilitate efficient completion of agreements.
Implementing document creation
Let’s proceed with implementing the document creation in your Node.js application. We need to create a dedicated route or API endpoint to handle this task. To accomplish this, use the BoldSign Node.js SDK to handle the request from your route and send the document. To initiate the signing process, you can make use of the BoldSign send API.
Here’s an example code snippet of how you can create a document from a template in your Node.js application.
import express from 'express';
import { TemplateApi } from 'boldsign';
import 'dotenv/config';
const app = express();
app.use(express.json());
const templateApi = new TemplateApi();
templateApi.setApiKey(process.env.BOLDSIGN_API_KEY);
// Define route for document creation and extract necessary data from request body
app.post('/create-document', async (req, res) => {
const { sellerName, sellerEmail, buyerName, buyerEmail, amount, address, templateId } = req.body;
const data = {
roles: [
{
roleIndex: 1,
signerName: sellerName,
signerEmail: sellerEmail,
existingFormFields: [
{
id: '<labelField1>',
value: address,
},
{
id: '<labelField2>',
value: amount,
},
],
},
{
roleIndex: 2,
signerName: buyerName,
signerEmail: buyerEmail,
formFields: [
{
fieldType: "Signature",
pageNumber: 1,
bounds: { x: 100, y: 300, width: 200, height: 50 },
}
],
}
],
disableEmails: true
};
const response = await templateApi.sendUsingTemplate(templateId, data);
const docId = response.documentId;
res.status(200).json({ success: true, documentId: docId}); // Send a success response with document ID
});
Generating the embedded signing URL
By default, BoldSign sends an email to the signers requesting them to sign and complete the contracts within the BoldSign application. Alternatively, you can use embedded signing by specifying the disableEmails parameter. This instructs BoldSign not to send emails to the signers, allowing you to configure the email process from your end once the document is created.
To generate an embedded signing URL, you can make use of the BoldSign getEmbeddedSignLink API. Here is an example code snippet to get the embedded sign link in a Node.js application.
import { DocumentApi } from 'boldsign';
import 'dotenv/config';
const documentApi = new DocumentApi();
documentApi.setApiKey(process.env.BOLDSIGN_API_KEY);
const docId = 'YOUR_DOCUMENT_ID';
const sellerEmail = 'SELLER_EMAIL_ADDRESS';
// If a redirect URL is specified, the iFrame will redirect users to it after they sign the document.
const redirectUrl = '{your-host}/{your-redirect-path}';
const result = await documentApi.getEmbeddedSignLink(docId, sellerEmail, null, null, null, redirectUrl);
// Get the embedded signing URL.
const signUrl = result.signLink;
To seamlessly integrate the signing process into your application, load the sign page URL, within an iframe on your application. This allows the recipient to interact with the signing page without leaving your site.
Integrate webhooks to download completed documents
You can integrate webhooks into your Node.js application to automate the process of downloading completed PDF documents and efficiently distribute them to the relevant parties. By subscribing to the DocumentCompleted event, which is triggered after all parties have signed the document, and the final PDF file is generated.
After the signing process is successfully completed, you can use the BoldSign Download API to download the signed document if you wish to save a copy for future use. The following code snippet illustrates this.
import { DocumentApi } from 'boldsign';
import 'dotenv/config';
import { writeFileSync } from 'fs';
const documentApi = new DocumentApi();
documentApi.setApiKey(process.env.BOLDSIGN_API_KEY);
const documentId = 'YOUR_DOCUMENT_ID';
// Download the PDF as a Buffer
const pdfBuffer = await documentApi.downloadDocument(documentId);
// Write the buffer to a PDF file
writeFileSync('FILE_NAME.pdf', pdfBuffer);
Upon receiving the Download Document API response, you can send emails containing the completed PDF files to the relevant parties. With webhooks in place, you can ensure timely delivery of signed documents to the concerned stakeholders, simplifying your document management process. Refer to the Webhooks documentation for further details and see the Verify Webhook Events guide for security best practices.
Conclusion
By leveraging the power of BoldSign, companies like real estate agencies can integrate eSignatures into your Node.js application and can streamline the contract signing process. Irrespective of your industry or scenario, the steps outlined in this blog post enable you to seamlessly integrate BoldSign into your Node.js application, enhancing the eSignature experience of your users.
To learn more about the BoldSign APIs, check out our API documentation. Live API demos are also available for several scenarios. Sample code for popular programming languages is available in this GitHub repo.
If you have questions, you can contact us through our support portal. We are always happy to assist you!
