DocuSign Node Client
[![Dependency Status] david-image]david-url
NPM module that wraps the DocuSign API
Documentation about the DocuSign API
Documentation about this package
You can sign up for a free developer sandbox.
============
Requirements
Node 0.10 or later.
Installation
NPM Package Manager
Install the client locally: npm install docusign-esign --save --save-exact
(note you may have to use sudo
based on your permissions)
Alternatively you can just copy the source code directly into your project.
Dependencies
This client has the following external dependencies:
Usage
To initialize the client, make the Login API Call and send a template for signature:
var docusign = require('docusign-esign');
var async = require('async');
var integratorKey = '***';
var email = 'YOUR_EMAIL';
var password = 'YOUR_PASSWORD';
var docusignEnv = 'demo';
var fullName = 'Joan Jett';
var recipientEmail = 'joan.jett@example.com';
var templateId = '***';
var templateRoleName = '***';
var baseUrl = 'https://' + docusignEnv + '.docusign.net/restapi';
var apiClient = new docusign.ApiClient();
apiClient.setBasePath(baseUrl);
var creds = JSON.stringify({
Username: email,
Password: password,
IntegratorKey: integratorKey
});
apiClient.addDefaultHeader('X-DocuSign-Authentication', creds);
docusign.Configuration.default.setDefaultApiClient(apiClient);
async.waterfall([
function login (next) {
var authApi = new docusign.AuthenticationApi();
var loginOps = new authApi.LoginOptions();
loginOps.setApiPassword('true');
loginOps.setIncludeAccountIdGuid('true');
authApi.login(loginOps, function (err, loginInfo, response) {
if (err) {
return next(err);
}
if (loginInfo) {
var loginAccounts = loginInfo.getLoginAccounts();
console.log('LoginInformation: ' + JSON.stringify(loginAccounts));
var loginAccount = loginAccounts[0];
var accountId = loginAccount.accountId;
var baseUrl = loginAccount.baseUrl;
var accountDomain = baseUrl.split("/v2");
apiClient.setBasePath(accountDomain[0]);
docusign.Configuration.default.setDefaultApiClient(apiClient);
next(null, loginAccount);
}
});
},
function sendTemplate (loginAccount, next) {
var envDef = new docusign.EnvelopeDefinition();
envDef.setEmailSubject('Please sign this document sent from Node SDK');
envDef.setTemplateId(templateId);
var tRole = new docusign.TemplateRole();
tRole.setRoleName(templateRoleName);
tRole.setName(fullName);
tRole.setEmail(recipientEmail);
var templateRolesList = [];
templateRolesList.push(tRole);
envDef.setTemplateRoles(templateRolesList);
envDef.setStatus('sent');
var accountId = loginAccount.accountId;
var envelopesApi = new docusign.EnvelopesApi();
envelopesApi.createEnvelope(accountId, envDef, null, function (err, envelopeSummary, response) {
if (err) {
return next(err);
}
console.log('EnvelopeSummary: ' + JSON.stringify(envelopeSummary));
next(null);
});
}
], function end (error) {
if (error) {
console.log('Error: ', error);
process.exit(1);
}
process.exit();
});
See CoreRecipes.js for more examples.
Authentication
(Legacy Header Authentication uses the X-DocuSign-Authentication header.)
- Use the Authentication: login method to retrieve the account number and the baseUrl for the account.
The url for the login method is www.docusign.net for production and demo.docusign.net for the developer sandbox.
The
baseUrl
field is part of the loginAccount
object. See the docs and the loginAccount object - The baseUrl for the selected account, in production, will start with na1, na2, na3, eu1, or something else. Use the baseUrl that is returned to create the basePath (see the next step.) Use the basePath for all of your subsequent API calls.
- As returned by login method, the baseUrl includes the API version and account id. Split the string to obtain the basePath, just the server name and api name. Eg, you will receive
https://na1.docusign.net/restapi/v2/accounts/123123123
. You want just https://na1.docusign.net/restapi
- Instantiate the SDK using the basePath. Eg
ApiClient apiClient = new ApiClient(basePath);
- Set the authentication header as shown in the examples by using
Configuration.Default.AddDefaultHeader
User Applications that use OAuth Authentication
- After obtaining a Bearer token, call the OAuth: Userinfo method. Obtain the selected account's
base_uri
(server name) field.
The url for the Userinfo method is account-d.docusign.com for the demo/developer environment, and account.docusign.com for the production environment. - Combine the base_uri with "/restapi" to create the basePath. The base_uri will start with na1, na2, na3, eu1, or something else. Use the basePath for your subsequent API calls.
- Instantiate the SDK using the basePath. Eg
ApiClient apiClient = new ApiClient(basePath);
- Create the
authentication_value
by combining the token_type
and access_token
fields you receive from either an Authorization Code Grant or Implicit Grant OAuth flow. - Set the authentication header by using
Configuration.Default.AddDefaultHeader('Authorization', authentication_value)
Testing
Unit tests are available in the Test folder.
Support
Feel free to log issues against this client through GitHub. We also have an active developer community on Stack Overflow, search the DocuSignAPI tag.
License
The DocuSign Node Client is licensed under the following License.
Notes
This version of the client library does not implement all of the DocuSign REST API methods. The current client omits methods in the Accounts, Billing, Cloud Storage, Connect, Groups (Branding), and Templates (Bulk Recipients) categories. The client's methods support the core set of use cases that most integrations will encounter. For a complete list of omitted endpoints, see Omitted Endpoints.