2015-05-04 86 views
0

我正在嘗試使用基於少數參數生成的PDF文檔獲取Docusign工作。工作流程是,用戶將生成PDF,然後當點擊一個按鈕時,它將帶有一個帶有該PDF的docusign iFrame。用戶標誌和docusign會將文檔發送給我們。 docusign中有很多優秀的API。希望有人會有一個符合這個縮小範圍的經驗。Docusign iFrame

-Thanks

回答

2

DocuSign Developer Center快速啓動 - >API工具並從那裏你會看到這樣的API資源管理器和API演練一些偉大的工具。 API Walkthroughs對於所有9種場景(包括Javascript(Node.js)),使用6種不同語言的示例代碼覆蓋了9種最常見的DocuSign API用例。

您需要的「窄」用例根本沒有縮小,它是這9個常用用例中的一個,我們有示例代碼。請參閱名爲的文件請求文件的簽名。按照說明覆制該代碼,在頂部填寫變量,並在同一文件夾中提供文檔,它將起作用。然後從那裏你可以做任何你需要的修改。

以下是一個演練實際的javascript:

// Request Signature on a Document (Node.js) 

// 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 
//  npm install fs 
// 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 
     documentName = "***",   // copy document with this name into same directory! 
     baseUrl = "";    // we will retrieve this 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: Request Signature on a PDF Document 
    ///////////////////////////////////////////////////////////////////////////////////// 
    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": email, 
        "name": recipientName, 
        "recipientId": 1, 
        "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) { 
      parseResponseBody(err, res, body); 
     }); 
    } // end function  
]); 

//*********************************************************************************************** 
// --- 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; 
} 
+0

謝謝!我有一個彈簧棧而不是NodeJS。但是我也看到了Java代碼庫。會給一個嘗試。, –