2

我有一个场景,我需要用户访问网站上传文档,而另一个用户必须签署此文档。

到目前为止我所做的:

Step1:通过邮箱、密码和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
        });
    },

我收到了有效的回复,包括有效的 accountID。

Step2:现在我正在通过这个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(当然!!)

第 3 步:现在我希望另一个用户(如上面提供的收件人电子邮件/姓名)在我的网站上的嵌入视图中签署此文档, 为此我正在使用此 API http://iodocs.docusign.com/APIWalkthrough/embeddedSigning#js 但这需要上面使用的 API 未返回给我们的 templateId 和角色。这需要手动上传模板并获取模板ID,这在我的场景中是不可能的,因为我希望一切都是自动的。

谁能指导我如何进行嵌入式签名。

文档签名API

4

2 回答 2

1

如果您希望签名者通过您的站点访问 Envelope,则需要在创建 Envelope 时将签名者指定为“嵌入式/强制”签名者。这是通过clientUserId在创建信封 API 请求中设置收件人对象的属性来完成的。(此属性可以设置为您选择的任何值——最大长度为 100 个字符,但您的应用程序需要跟踪它,因为当收件人访问您的站点时,您需要它来启动收件人的签名会话。)

所以,它是这样工作的:

  1. 您的应用程序通过“创建信封”API 请求创建信封,设置 clientUserId收件人(签名者)的属性以指示他们将通过您的应用程序访问信封。为了这个示例,假设您将clientUserId设置为1234

    “签名者”:[{ “电子邮件”:“janesemail@outlook.com”,“名称”:“Jane Doe”,“recipientId”:1,“clientUserId”:1234 }]

  2. 您的应用程序通知签名者(通过电子邮件)需要在文件上签名;该电子邮件提供了有关他们如何通过您的站点访问信封(即签署文件)的信息。(DocuSign 不会向指定为嵌入/强制的收件人发送“签名邀请”电子邮件。)

  3. 签名者遵循您的应用程序发送给他们的电子邮件中的指示,并访问您的站点以签署他们的文档。当签名者准备好签名时,您的应用程序会提交“ POST Recipient View ”API 请求以获取将为指定收件人启动 DocuSign 签名会话的 URL。请求如下所示:

.

POST https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes/{{envelopeId}}/views/recipient

{
     "authenticationMethod": "Email",
     "clientUserId": "1234",
     "userName": "Jane Doe",
     "email": "janesemail@outlook.com",
     "returnUrl": "URLInYourAppThatDocuSignRedirectsToWhenDocuSignSessionIsCompleted"
}

对此请求的响应将包含一个 URL,您的应用程序可以使用该 URL 启动收件人的签名会话。

于 2014-03-14T15:03:29.167 回答
0

Node.js这是您要完成的工作的完整工作示例。您想要做的是将在文档上发送签名请求的API 演练结合起来(以便它不使用模板),并将其与嵌入式签名 api 演练中的第三个调用结合起来。

要将嵌入式收件人添加到信封,您需要将其clientUserId属性设置为任何用户可配置的值。例如,您可以将其设置为“1”、“1234”或“1a2b3c”。在下面的代码中,我将其设置为“1001”以突出显示您可以将其设置为您喜欢的任何内容,您只需要跟踪它即可。 一个重要注意事项:您必须确保在为收件人请求嵌入式签名 URL 时,您引用的内容与clientUserId您最初将其添加到信封时设置的完全相同(以下示例中的 1001)。

这是代码:

// 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;
}
于 2014-03-14T21:37:39.680 回答