Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var DOCUSIGN_URL='xxx';
- var DOCUSIGN_USER='xxx';
- var DOCUSIGN_PASS='xxx';
- var DOCUSIGN_KEY='xxx';
- (function () {
- var apiClient = new docusign.ApiClient();
- apiClient.setBasePath(DOCUSIGN_URL);
- apiClient.addDefaultHeader('X-DocuSign-Authentication', JSON.stringify({
- Username: DOCUSIGN_USER,
- Password: DOCUSIGN_PASS,
- IntegratorKey: DOCUSIGN_KEY
- }));
- docusign.Configuration.default.setDefaultApiClient(apiClient);
- var loginData;
- async.waterfall([
- // Make sure login works.
- function (next) {
- var authenticationApi = new docusign.AuthenticationApi();
- var loginOps = new authenticationApi.LoginOptions();
- // loginOps.setApiPassword('true');
- loginOps.setIncludeAccountIdGuid('true');
- authenticationApi.login(loginOps, function (err, result, response) {
- // console.log(response.request.req._headers);
- // console.log(response.body);
- if (err) {
- return next(err);
- }
- if (result) {
- loginData = result.loginAccounts[0];
- console.log(result);
- return next();
- }
- next(new Error('Protocol Error'));
- });
- },
- // List templates
- function (next) {
- var templatesApi = new docusign.TemplatesApi();
- templatesApi.listTemplates(loginData.accountId, function (err, result, response) {
- if (err) {
- return next(err);
- }
- if (result) {
- console.log(result.envelopeTemplates);
- return next(null, result.getEnvelopeTemplates());
- }
- next(new Error('Protocol Error'));
- });
- },
- // Get Document template
- function (templates, next) {
- var templatesApi = new docusign.TemplatesApi();
- if (templates.length == 0) {
- next(new Error('No templates found'));
- }
- var documentTemplate = templates[0];
- if (!documentTemplate) {
- return next(new Error('Template error'));
- }
- console.log(loginData.accountId, documentTemplate.templateId);
- templatesApi.get(loginData.accountId, documentTemplate.templateId, function (err, result, response) {
- if (err) {
- return next(err);
- }
- if (result) {
- console.log(result);
- // return next(null, result.getEnvelopeTemplates());
- }
- // next(new Error('Protocol Error'));
- });
- }
- ], function (err, result) {
- if (err) {
- console.error('Failure:', err.stack);
- } else {
- console.log('Success');
- }
- })
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement