DocuSign嵌入式签名API

时间:2015-06-23 19:04:17

标签: node.js html5 docusignapi

两部分问题:

我们正在尝试接收文档已准备好签名的通知(我们对通知中提供的内容并不完全清楚)。我们不想做电子邮件通知;我们要关闭那些。我们假设嵌入式签名的信息包含在非电子邮件通知中。是否有一种简单的方法可以将推送通知发送到另一个程序,表明文档已准备好发送,如果是,是跟进通知以获得签名API POST并从DocuSign请求信息的最佳方式吗?

在我们的测试中,我们已经能够通过API调用接收嵌入式签名URL,但它会将我们转到签名视图的页面,其中标签未显示;这意味着签名者无法签名,同样也适用于其他角色。在this SO帖子中解释的问题大部分都是如此。我用JavaScript编写代码,而不是PHP代码。我不知道这是否会在回答问题方面有所作为,如果是这样,请在评论中提出更多问题,我可以提供更多信息。

This is what we're getting, but we are supposed to be getting a document with the signature tabs in it. 这是我们正在获取的内容,但我们应该会在其中获取包含签名标签的文档

This is what we're supposed to see. We see this version when manually logging into DS and clicking on the doc. 这是我们应该看到的。我们在手动登录DS并单击文档时会看到此版本。

我们认为templateRoleName字段可能是导致此问题的原因,但我们已经测试过它和不带它,它似乎没有什么区别。

这是我们从演练中使用的API调用的JS文件。

//
// 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;
    }

修改 enter image description here 这是此模板的DocuSign经典视图中的收件人和路由部分,因为它是此问题的原始发布

这是请求日志中的Created_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"
}

这是请求日志中的Created_CreateEnvelopeFromTemplateAndForms文件:

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"
}

thisthisthis不是此帖的解决方案。

1 个答案:

答案 0 :(得分:2)

如果您希望收件人继承您之前创建的所有选项卡和工作流,则从模板发送签名请求时,您必须将它们与角色匹配。要匹配它们,您需要使用roleName属性,该属性是通过您引用的templateRoleName示例节点脚本设置的。

首先,我想提一下,在第一个没有标签的屏幕截图中,收件人仍然可以通过将左侧的任何标签拖到文档上来签名。这称为自由格式签名,当他们与模板角色不匹配时,他们会选择将哪些标签,多少以及放在文档上的位置。

我在您的代码中看到您将模板角色名称设置为值Signer,只有当您在Web控制台中将其命名为占位符(模板)角色时才会起作用正在创造它。将Web控制台中角色名称的值更改为Signer,它应该可以正常工作。