/DocuSign-Node-Client

DocuSign eSignature NPM Package

Primary LanguageJavaScriptOtherNOASSERTION

DocuSign Node Client

NPM version NPM downloads Build status Test coverage

NPM module that wraps the DocuSign API

Documentation about the DocuSign API

Documentation about this package

Changelog

Feel free to create a Pull Request!

Pre-requisites

DocuSign Developer account (Free)

You can create your free dev account at the DocuSign DevCenter using this registration form. You will need the Integrator Key from your developer account in order to use the DocuSign Node Client Library.

Useful Reading

See Common Terms for an explanation of the basic components of the DocuSign platform.

Getting Started

Install the client locally: npm install docusign --save --save-exact (note you may have to use sudo based on your permissions)

The below examples show you how to:

  • Create a DocuSign Object with an Integrator Key and a Target DocuSign Environment
  • Create a DocuSign Client Object and Login using your DocuSign Account Credentials
  • Create a new Envelope using a Template and sending to the recipient you specify
  • Logout of the Client by Revoking the DocuSign user's OAuth Token

Alternatively, this SDK supports a promise interface via bluebird. An example is provided.

var docusign = require('docusign');
var async = require('async');

var integratorKey  = '***',                   // Integrator Key associated with your DocuSign Integration
  email            = 'YOUR_EMAIL',            // Email for your DocuSign Account
  password         = 'YOUR_PASSWORD',         // Password for your DocuSign Account
  docusignEnv      = 'demo',                  // DocuSign Environment generally demo for testing purposes
  fullName         = 'Joan Jett',             // Recipient's Full Name
  recipientEmail   = 'joan.jett@example.com', // Recipient's Email
  templateId       = '***',                   // ID of the Template you want to create the Envelope with
  templateRoleName = '***',                   // Role Name of the Template
  debug            = false;                   // Enable debug logging and debug responses from API

var templateRoles = [{
  email: email,
  name: fullName,
  roleName: templateRoleName
}];
var additionalParams = {};

async.waterfall([
  // **********************************************************************************
  // Step 1 - Initialize DocuSign Object with Integrator Key and Desired Environment
  // **********************************************************************************
  function init (next) {
    docusign.init(integratorKey, docusignEnv, debug, function(err, response) {
      if (err) {
        return next(err);
      }
      if (response.message === 'successfully initialized') {
        next();
      }
    });
  },

  // **********************************************************************************
  // Step 2 - Create a DocuSign Client Object
  // **********************************************************************************
  function createClient (next) {
    docusign.createClient(email, password, function(err, client) {
      if (err) {
        return next(err);
      }
      next(null, client);
    });
  },

  // **********************************************************************************
  // Step 3 - Request Signature via Template
  // **********************************************************************************
  function sendTemplate (client, next) {
    client.envelopes.sendTemplate('Sent from a Template', templateId, templateRoles, additionalParams, function (err, response) {
      if (err) {
        return next(err);
      }
      console.log('The envelope information of the created envelope is: \n' + JSON.stringify(response));
      next(null, client);
    });
  },

  // **********************************************************************************
  // Step 4 - Revoke OAuth Token for Logout
  // **********************************************************************************
  function logOut (client, next) {
    client.logOut(function (err, response) {
      if (err) {
        return next(err);
      }
      next(null);
    });
  }

], function end (error) {
  if (error) {
    console.log('Error: ', error);
    process.exit(1)
  }
  process.exit()
});

How to run Unit Tests

In the console run npm test.

Contributing

Pull requests and new issues are welcomed and encouraged! We follow the semistandard style, please make your contributions conform to this.

License

The DocuSign-Node-Client is licensed under the following LICENSE.