Node.js DocuSign嵌入式签名API
问题分两部分: 我们正试图收到一份文件准备签署的通知(我们不完全清楚通知中提供了什么)。我们不想做电子邮件通知;我们想关掉那些。我们假定嵌入签名的信息包含在非电子邮件通知中。是否有一种简单的方法可以将推送通知发送到另一个表示文档已准备好发送的程序,如果是,那么跟踪通知以发布签名API并从DocuSign请求信息的最佳方法是什么 在我们的测试中,我们已经能够通过API调用接收嵌入的签名URL,但它会将我们带到一个页面,指向一个签名视图,其中没有显示选项卡;这意味着签名者不能签名,对于其他角色也是如此。大部分情况下,这和SO帖子中解释的问题是一样的。我用的是JavaScript,不是PHP。我不知道这是否会对回答问题产生影响,如果是,请在评论中提出更多问题,我可以提供更多信息 这是我们得到的,但我们应该得到一个带有签名标签的文档 这就是我们应该看到的。手动登录DS并单击文档时,我们会看到此版本。 我们相信templateRoleName字段可能是导致此问题的原因,但我们已经测试了有无该字段,似乎没有什么区别 这是我们在演练中使用的API调用的JS文件Node.js DocuSign嵌入式签名API,node.js,html,docusignapi,Node.js,Html,Docusignapi,问题分两部分: 我们正试图收到一份文件准备签署的通知(我们不完全清楚通知中提供了什么)。我们不想做电子邮件通知;我们想关掉那些。我们假定嵌入签名的信息包含在非电子邮件通知中。是否有一种简单的方法可以将推送通知发送到另一个表示文档已准备好发送的程序,如果是,那么跟踪通知以发布签名API并从DocuSign请求信息的最佳方法是什么 在我们的测试中,我们已经能够通过API调用接收嵌入的签名URL,但它会将我们带到一个页面,指向一个签名视图,其中没有显示选项卡;这意味着签名者不能签名,对于其他角色也是如
//
// to run this sample
// 1. copy the file in your own directory - say, example.js
// 2. change "***" to appropriate values
// 3. install async and request packages
// npm install async
// npm install request
// 4. execute
// node example.js
//
var async = require("async"), // async module
request = require("request"), // request module
email = "email@email.com", // your account email
password = "password1", // your account password
integratorKey = "DEEZ-010ebc24-01cc-143a-98c3-d9dbf7561cb1", // your account Integrator Key (found on Preferences -> API page)
recipientName = "email@email.com", // recipient (signer) name
templateId = "1C504DBA-B03F-4E57-B6BB-FD2ABD15837C", // provide valid templateId from a template in your account
templateRoleName = "Signer", // template role that exists on template referenced above
baseUrl = "", // we will retrieve this
envelopeId = "bc14310c-57c0-4168-91be-1fb71ea24c1c"; // created from step 2
async.waterfall(
[
//////////////////////////////////////////////////////////////////////
// Step 1 - Login (used to retrieve accountId and baseUrl)
//////////////////////////////////////////////////////////////////////
function(next) {
var url = "https://demo.docusign.net/restapi/v2/login_information";
var body = ""; // no request body for login api call
// set request url, method, body, and headers
var options = initializeRequest(url, "GET", body, email, password);
// send the request...
request(options, function(err, res, body) {
if(!parseResponseBody(err, res, body)) {
return;
}
baseUrl = JSON.parse(body).loginAccounts[0].baseUrl;
next(null); // call next function
});
},
//////////////////////////////////////////////////////////////////////
// Step 2 - Send envelope with one Embedded recipient (using clientUserId property)
//////////////////////////////////////////////////////////////////////
function(next) {
var url = baseUrl + "/envelopes";
var body = JSON.stringify({
"emailSubject": "DocuSign API call - Embedded Sending Example",
"templateId": templateId,
"templateRoles": [{
"email": email,
"name": recipientName,
"roleName": templateRoleName,
"clientUserId": "1001" // user-configurable
}],
"status": "sent"
});
// set request url, method, body, and headers
var options = initializeRequest(url, "POST", body, email, password);
// send the request...
request(options, function(err, res, body) {
if(!parseResponseBody(err, res, body)) {
return;
}
// parse the envelopeId value from the response
envelopeId = JSON.parse(body).envelopeId;
next(null); // call next function
});
},
//////////////////////////////////////////////////////////////////////
// Step 3 - Get the Embedded Signing View (aka the recipient view)
//////////////////////////////////////////////////////////////////////
function(next) {
var url = baseUrl + "/envelopes/" + envelopeId + "/views/recipient";
var method = "POST";
var body = JSON.stringify({
"returnUrl": "http://www.docusign.com/devcenter",
"authenticationMethod": "email",
"email": email,
"userName": recipientName,
"clientUserId": "1001", // must match clientUserId in step 2!
});
// set request url, method, body, and headers
var options = initializeRequest(url, "POST", body, email, password);
// send the request...
request(options, function(err, res, body) {
if(!parseResponseBody(err, res, body))
return;
else
console.log("\nNavigate to the above URL to start the Embedded Signing workflow...");
});
}
]);
//***********************************************************************************************
// --- HELPER FUNCTIONS ---
//***********************************************************************************************
function initializeRequest(url, method, body, email, password) {
var options = {
"method": method,
"uri": url,
"body": body,
"headers": {}
};
addRequestHeaders(options, email, password);
return options;
}
///////////////////////////////////////////////////////////////////////////////////////////////
function addRequestHeaders(options, email, password) {
// JSON formatted authentication header (XML format allowed as well)
dsAuthHeader = JSON.stringify({
"Username": email,
"Password": password,
"IntegratorKey": integratorKey // global
});
// DocuSign authorization header
options.headers["X-DocuSign-Authentication"] = dsAuthHeader;
}
///////////////////////////////////////////////////////////////////////////////////////////////
function parseResponseBody(err, res, body) {
console.log("\r\nAPI Call Result: \r\n", JSON.parse(body));
if( res.statusCode != 200 && res.statusCode != 201) { // success statuses
console.log("Error calling webservice, status is: ", res.statusCode);
console.log("\r\n", err);
return false;
}
return true;
}
编辑
这是DocuSign的经典视图中的收件人和发送部分,该模板与此问题的原始发布相同
这是从请求日志创建的\u RequestRecipientToken文件:
POST https://demo.docusign.net:7802/restapi/v2/accounts/1037192/envelopes/deez83c9-b1fg-46ab-bo0c-e4576d952ac6/views/recipient
Content-Length: 185
Connection: keep-alive
Host: demo.docusign.net
X-DocuSign-Authentication: {"Username":"sender@email.com","Password":"[omitted]","IntegratorKey":"[omitted]"}
X-Forwarded-For: 543.155.155.55
{"returnUrl":"http://www.docusign.com/devcenter","authenticationMethod":"email","email":"sender@email.com","userName":"signer@email.com","clientUserId":"1002"}
201 Created
Content-Type: application/json; charset=utf-8
{
"url": "https://demo.docusign.net/Signing/startinsession.aspx?t=3c06d2a3-e521-4e52-b669-01e24c81c3bf"
}
POST https://demo.docusign.net:7802/restapi/v2/accounts/1037192/envelopes
Content-Length: 272
Connection: keep-alive
Host: demo.docusign.net
X-DocuSign-Authentication: {"Username":"sender@email.com","Password":"[omitted]","IntegratorKey":"[omitted]"}
X-Forwarded-For: 143.115.155.55
{"emailSubject":"DocuSign API call - Embedded Sending Example","templateId":"9AF271E2-D38E-4E61-8083-928A3CCE056C",
"templateRoles":[{"email":"sender@email.com","name":"signer@email.com","roleName":"Signer","clientUserId":"1002"}],
"status":"sent"}
201 Created
Content-Type: application/json; charset=utf-8
{
"envelopeId": "deez83c9-b1fg-46ab-bo0c-e4576d952ac6",
"uri": "/envelopes/deez83c9-b1fg-46ab-bo0c-e4576d952ac6",
"statusDateTime": "2015-07-08T15:56:23.5930000Z",
"status": "sent"
}
这是从请求日志中创建的\u CreateEnvelopeFromTemplateAndForms文件:
POST https://demo.docusign.net:7802/restapi/v2/accounts/1037192/envelopes/deez83c9-b1fg-46ab-bo0c-e4576d952ac6/views/recipient
Content-Length: 185
Connection: keep-alive
Host: demo.docusign.net
X-DocuSign-Authentication: {"Username":"sender@email.com","Password":"[omitted]","IntegratorKey":"[omitted]"}
X-Forwarded-For: 543.155.155.55
{"returnUrl":"http://www.docusign.com/devcenter","authenticationMethod":"email","email":"sender@email.com","userName":"signer@email.com","clientUserId":"1002"}
201 Created
Content-Type: application/json; charset=utf-8
{
"url": "https://demo.docusign.net/Signing/startinsession.aspx?t=3c06d2a3-e521-4e52-b669-01e24c81c3bf"
}
POST https://demo.docusign.net:7802/restapi/v2/accounts/1037192/envelopes
Content-Length: 272
Connection: keep-alive
Host: demo.docusign.net
X-DocuSign-Authentication: {"Username":"sender@email.com","Password":"[omitted]","IntegratorKey":"[omitted]"}
X-Forwarded-For: 143.115.155.55
{"emailSubject":"DocuSign API call - Embedded Sending Example","templateId":"9AF271E2-D38E-4E61-8083-928A3CCE056C",
"templateRoles":[{"email":"sender@email.com","name":"signer@email.com","roleName":"Signer","clientUserId":"1002"}],
"status":"sent"}
201 Created
Content-Type: application/json; charset=utf-8
{
"envelopeId": "deez83c9-b1fg-46ab-bo0c-e4576d952ac6",
"uri": "/envelopes/deez83c9-b1fg-46ab-bo0c-e4576d952ac6",
"statusDateTime": "2015-07-08T15:56:23.5930000Z",
"status": "sent"
}
或不是此帖子的解决方案。当您从模板发送签名请求时,如果希望收件人继承您以前创建的所有选项卡和工作流,则必须将其与角色匹配。要匹配它们,需要使用
roleName
属性,该属性是通过引用的templateRoleName
示例节点脚本设置的
首先,我想提到的是,在您的第一个屏幕截图中,如果没有选项卡,收件人仍然可以通过将任何选项卡从左侧拖动到文档上来签名。这称为自由形式签名,当标签与模板角色不匹配时,他们选择了哪些标签、数量以及在文档上放置标签的位置
我在您的代码中看到,您正在将模板角色名称设置为value
Signer
,仅当您在创建占位符(模板)角色时在web控制台中将其命名为该值时,这才有效。将web控制台中角色名称的值更改为Signer
,它应该可以工作 我补充了一些信息以回应你的回答。请参见编辑部分。另外,新图像是否就是您所说的web控制台?是否可以使用此API直接将用户带到非自由格式签名(请参阅第一个图像)模板?这是最终目标。是的,你可以通过API直接让用户进入模板(非自由形式)签名体验。如前所述,您只需将它们与您在帐户模板中设置的角色匹配即可。我认为问题在于,您已经定义了3个角色,都是按1的顺序排列的,但只指定了其中一个角色。作为测试,请尝试命名其他两个角色(可能是Signer2和Signer3),并分别更改为路由顺序2。然后再次运行代码,它应该可以工作。好的,我删除了不是签名者的重复的角色
(如图所示),并将路由顺序更改为顺序顺序(1和2)。不过,我得到的是自由形式的
签名,而不是引导的
签名版本的文档。我已经完成了所有建议。我猜想它与发送envelopeID
和/或templateID
有关。只需要一个还是两个都需要?如果您能在这里提供任何额外的信息,我们将不胜感激。好的,现在最好的做法是发布您的代码正在发送的请求(如果您需要,您可以编辑文档字节和任何其他私有数据)。模板角色绝对适合我,所以我很确定您的请求有问题。此处缺少clientUserId字段