我只是试图使用Docusign API for NodeJS来获得我正在构建的应用程序的文档签名集成。我认为我已经完成了基本的身份验证握手。我在/docusign
和/docusign/auth
上创建了测试路由,并且可以使用以下代码获取访问令牌。
我只想从我已经作为临时模板上传的文档中获得电子邮件中的测试签名链接,但是createEnvelope调用最终陷入了错误:
USER_AUTHENTICATION_FAILED
One or both of Username and Password are invalid. Invalid access token
provide.generateAccessToken = (req, res, next) => {
apiClient.generateAccessToken(integratorKey, clientSecret, req.query.code, function (err, oAuthToken) {
console.log(oAuthToken);
apiClient.setBasePath(basePath);
//IMPORTANT: In order to access the other api families, you will need to add this auth header to your apiClient.
apiClient.addDefaultHeader('Authorization', 'Bearer ' + oAuthToken.accessToken);
var envelopesApi = new docusign.EnvelopesApi();
envelopesApi.apiClient.addDefaultHeader('Authorization', 'Bearer ' + oAuthToken.accessToken);
apiClient.getUserInfo(oAuthToken.accessToken, function (err, userInfo) {
console.log("UserInfo: " + userInfo);
// parse first account's baseUrl
// below code required for production, no effect in demo (same
// domain)
//apiClient.setBasePath(userInfo.accounts[0].baseUri + "/restapi");
// create a new envelope object that we will manage the signature request through
var envDef = new docusign.EnvelopeDefinition();
envDef.emailSubject = 'Rental Application';
envDef.templateId = '66c8c9cf-xxx-xxxx-xxxx-xxxxxxxx';
// create a template role with a valid templateId and roleName and assign signer info
var tRole = new docusign.TemplateRole();
tRole.roleName = 'Applicant';
tRole.name = 'test';
tRole.email = 'myemailtest@gmail.com';
// create a list of template roles and add our newly created role
var templateRolesList = [];
templateRolesList.push(tRole);
// assign template role(s) to the envelope
envDef.templateRoles = templateRolesList;
// send the envelope by setting |status| to 'sent'. To save as a draft set to 'created'
envDef.status = 'sent';
// use the |accountId| we retrieved through the Login API to create the Envelope
var accountId = userInfo.sub;
// instantiate a new EnvelopesApi object
// call the createEnvelope() API
envelopesApi.createEnvelope(accountId, {'envelopeDefinition': envDef}, function (err, envelopeSummary, response) {
if (err) {
return next(err);
}
console.log('EnvelopeSummary: ' + JSON.stringify(envelopeSummary));
return JSON.stringify(envelopeSummary);
});
});
});
}
任何向我指出正确方向的帮助将不胜感激!
谢谢!
答案 0 :(得分:1)
代替
var envelopesApi = new docusign.EnvelopesApi();
尝试
var envelopesApi = new docusign.EnvelopesApi(apiClient);
另外,对于具有DocuSign和授权代码授予的Node的工作示例,请查看此example.