Docusign:在没有templateID的情况下获取嵌入式收件人视图 [英] Docusign: Getting an embedded recipient view without having templateID

查看:145
本文介绍了Docusign:在没有templateID的情况下获取嵌入式收件人视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,我需要用户访问网站上载文档,而另一个用户必须签署该文档。

I have scenario where I need users coming on a web site to upload a document and another user has to sign this document.

到目前为止,我已经做过的事情:

What I have done till now:

第一步:通过电子邮件,密码和Integratorkey登录

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
        });
    },

我收到的有效回复包括有效的帐户ID。

I'm getting valid response including valid accountID.

第二步:现在我正在通过此api上传文档

function(next) {    
        var url = baseUrl + "/envelopes";
        // following request body will place 1 signature tab 100 pixels to the right and
        // 100 pixels down from the top left of the document that you send in the request
        var body = {
            "recipients": {
                "signers": [{
                    "email": recipientEmail,
                    "name": recipientName,
                    "recipientId": 1,
                    "tabs": {
                        "signHereTabs": [{
                            "xPosition": "100",
                            "yPosition": "100",
                            "documentId": "1",
                            "pageNumber": "1"                                                                                   
                        }]
                    }
                }]
            },
            "emailSubject": 'checkkkkkkkk API !!!!!',
            "documents": [{
                "name": "abc.pdf",
                "documentId": 1,
            }],
            "status": "sent",
        };
        
        // set request url, method, body, and headers
        var options = initializeRequest(url, "POST", body, email, password);
    
        // change default Content-Type header from "application/json" to "multipart/form-data"
        options.headers["Content-Type"] = "multipart/form-data";
        
        // configure a multipart http request with JSON body and document bytes
        options.multipart = [{
                    "Content-Type": "application/json",
                    "Content-Disposition": "form-data",
                    "body": JSON.stringify(body),
                }, {
                    "Content-Type": "application/pdf",
                    'Content-Disposition': 'file; filename="' + documentName + '"; documentId=1',
                    "body": fs.readFileSync(documentName),
                }
        ];
 
        // send the request...
        request(options, function(err, res, body) {
            parseResponseBody(err, res, body);
            envelopeId = JSON.parse(body).envelopeId;
            console.log(envelopeId);
            next(null);
        });

    }, 

在这里,我得到一个有效的EnvelopeID(肯定! )

Here in response I'm getting a valid EnvelopeID(for sure!!)

第3步:现在,我希望另一个用户(如receiveEmail / name上方所提供)在我的网站上的嵌入视图中对此文档签名
我正在使用此API http://iodocs.docusign.com/APIWalkthrough/embeddedSigning#js
,但这需要一个templateId和一个角色,上述使用的API并未将其返回给我们。

Step3: Now I want another user(as provided above recipientEmail/name) to sign this document in embed view on my website for this I'm using this API http://iodocs.docusign.com/APIWalkthrough/embeddedSigning#js but this requires a templateId and role which was not returned to us by the above used APIs. this needs manual effort to upload template and get templateID which is not possible in my scenario because I want everything to be automatic.

有人可以指导我如何继续进行嵌入式签名。

Can anyone direct me how to proceed with embedded signing.

推荐答案

以下是 Node.js中的完整工作示例您要完成的工作。您想要做的是结合 API演练,该函数在文档上发送签名请求(这样就不会使用模板),并将其与Embedded Signing API演练中的第三个调用结合起来。

Here is a FULL working sample in Node.js of what you are trying to accomplish. What you want to do is combine the API Walkthrough that sends a signature request on a document (so that it's not using template) and combine that with the third call in the Embedded Signing api walkthrough.

要将嵌入式收件人添加到信封,您需要将其 clientUserId 属性设置为任何用户可配置的值。例如,您可以将其设置为 1, 1234或 1a2b3c。在下面的代码中,我将其设置为 1001,以突出显示您可以将其设置为任意值,您只需要对其进行跟踪即可。 重要提示:您必须确保在请求收件人的嵌入式签名URL时,您引用的是与您设置时完全相同的 clientUserId 首先将它们添加到信封中(在下面的示例中为1001)。

To add an Embedded recipient to an envelope you need to set their clientUserId property to any user-configurable value. For instance, you could set it to just "1", or "1234", or "1a2b3c". In my code below I have set it to "1001" to highlight that you can set it to whatever you like, you just need to keep track of it. One important note: You must make sure that when requesting the Embedded Signing URL for the recipient that you reference the same exact clientUserId that you set when you initially added them to the envelope (1001 in the below example).

这里是代码:

// To run this sample
//  1. Copy the file to your local machine and give .js extension (i.e. 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
        fs = require("fs");         // fs module

var     email = "***",              // your account email
        password = "***",           // your account password
        integratorKey = "***",      // your Integrator Key (found on the Preferences -> API page)
        recipientName = "***",      // recipient (signer) name
        recipientEmail = "***",     // recipient email address  
        documentName = "***",       // copy document with this name into same directory!
        envelopeId = "",            // will retrieve this from second api call
        baseUrl = "";               // retrieved through the Login call

async.waterfall(
  [
    /////////////////////////////////////////////////////////////////////////////////////
    // Step 1: Login (used to retrieve your 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: Create Envelope with Embedded Recipient (need to set |clientUserId| property)
    /////////////////////////////////////////////////////////////////////////////////////
    function(next) {    
        var url = baseUrl + "/envelopes";
        // following request body will place 1 signature tab 100 pixels to the right and
        // 100 pixels down from the top left of the document that you send in the request
        var body = {
            "recipients": {
                "signers": [{
                    "email": recipientEmail,
                    "name": recipientName,
                    "recipientId": 1,
                    "clientUserId": "1001",     //Required for embedded recipient
                    "tabs": {
                        "signHereTabs": [{
                            "xPosition": "100",
                            "yPosition": "100",
                            "documentId": "1",
                            "pageNumber": "1"                                                                                   
                        }]
                    }
                }]
            },
            "emailSubject": 'DocuSign API - Signature Request on Document Call',
            "documents": [{
                "name": documentName,
                "documentId": 1,
            }],
            "status": "sent"
        };

        // set request url, method, body, and headers
        var options = initializeRequest(url, "POST", body, email, password);

        // change default Content-Type header from "application/json" to "multipart/form-data"
        options.headers["Content-Type"] = "multipart/form-data";

        // configure a multipart http request with JSON body and document bytes
        options.multipart = [{
                    "Content-Type": "application/json",
                    "Content-Disposition": "form-data",
                    "body": JSON.stringify(body),
                }, {
                    "Content-Type": "application/pdf",
                    'Content-Disposition': 'file; filename="' + documentName + '"; documentId=1',
                    "body": fs.readFileSync(documentName),
                }
        ];

        // send the request...
        request(options, function(err, res, body) {
            if(!parseResponseBody(err, res, body)) {
                return;
            }
            envelopeId = JSON.parse(body).envelopeId;
            next(null); // call next function
        });
    }, // end function    

    /////////////////////////////////////////////////////////////////////////////////////
    // Step 3: Generate the Embedded Signing URL
    /////////////////////////////////////////////////////////////////////////////////////

    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:在没有templateID的情况下获取嵌入式收件人视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆