Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post Go Live issue with Docusign using node.js

Here is my issue:

  • We integrated docusign in our application, server side with nodejs using this tutorial https://github.com/docusign/docusign-node-client ("OAuth JSON Web Token (JWT) Grant" section)
  • We have done the "Go Live Process": our application is registered in our production account
  • We have replaced the test config to the production config.
  • When we try to create an envelope, we get the following error: PARTNER_AUTHENTICATION_FAILED: The specified Integrator Key was not found or is disabled. Invalid account specified for user

What am I doing wrong ?

async function docusignInit() {
    var options;
    var env = [40077,50077].indexOf(config.main.port) != -1 ? 'test' :'prod';
    if (env == "test") {
        options = {
            basePath: restApi.BasePath.DEMO,
            oAuthBasePath: oAuth.BasePath.DEMO
        }
    } else {
        options = {
            oAuthBasePath: "account.docusign.com",
           // We called https://account.docusign.com/oauth/userinfo to found the uri
            basePath:"https://eu.docusign.net/restapi/"
        }
    }
    // in production, We must do
    // var apiClient = new docusign.ApiClient(options.basePath);
    // Otherwise, we get "Error: getaddrinfo ENOTFOUND undefined undefined:443"
    var apiClient = new docusign.ApiClient(options.basePath);
    var privateKeyFile = fs.readFileSync(`./server/docusign/keys/${env}/private.PEM`);
    var res = await apiClient.requestJWTUserToken(config.docusign.integratorKey, config.docusign.userName, [oAuth.Scope.IMPERSONATION, oAuth.Scope.SIGNATURE], privateKeyFile, 3600)
    var token = res.body.access_token;
    apiClient.addDefaultHeader('Authorization', 'Bearer ' + token);
    docusign.Configuration.default.setDefaultApiClient(apiClient);
    await sendDocusign({
        userId: 1,
        firstName: 'foor',
        lastName: 'bar',
        email:'foo@bar;'
    })
}


async function sendDocusign(role) {

    var envDef = new docusign.EnvelopeDefinition();
    envDef.emailSubject = 'Please signe this';
    envDef.templateId = config.docusign.templateId;

    var role = new docusign.TemplateRole();
    role.roleName = "roleName";
    role.clientUserId = role.userId;
    role.name = role.firstName + " " + role.lastName;
    role.email = role.email;

    envDef.allowReassign = false;
    envDef.templateRoles = [role];
    envDef.status = 'sent';

    var envelopesApi = new docusign.EnvelopesApi();
    return await envelopesApi.createEnvelope(config.docusign.userAccountId, {
        'envelopeDefinition': envDef
    })
}
like image 478
Arnaud Avatar asked Apr 26 '19 14:04

Arnaud


1 Answers

As you are able to generate AccesToken properly in PROD with PROD RSA KeyPair, so please check the endpoint which you using to make API calls to create an envelope. In demo it is always demo.docusign.net but in PROD it will be a different value depending on where you PROD account exists in the DocuSign data center. For instance if your PROD account is in NA1, then hostname will be will be www.docusign.net; if it is NA2 then hostname will be na2.docusign.net etc.

So it is recommended to make a /userinfo API call with the Access token to know the baseURI to make calls related to envelope. To get the base URI, call the /oauth/userinfo endpoint, supplying your application’s access token as a header.

  • For the developer sandbox environment, the URI is https://account-d.docusign.com/oauth/userinfo
  • For the production environment, the URI is https://account.docusign.com/oauth/userinfo

Documentation related to /userinfo API call is available here. Once you know you BaseURI then append this baseURI with envelopes related endpoint like below:

{base_uri} + "/restapi/v2.1/accounts/" + {account_id}
like image 125
Amit K Bist Avatar answered Nov 14 '22 22:11

Amit K Bist