2017-06-05 53 views
0

我正在處理DocuSign集成。我有基本的功能,但似乎無法弄清楚如何將本地文檔(PDF)與服務器模板合併,以便在服務器模板上配置的選項卡在傳遞的文檔上得到使用或覆蓋。Docusign API服務器模板本地文檔和選項卡

我的模板在服務器上定義,我可以直接從Web UI使用它(沒有問題)(這是一個W4表單)。您可以在下面看到該模板有三個選項卡(SSN,Sign here和日期)。訪問此模板通過它使用API​​瀏覽器ID產生以下JSON

{ 
    "envelopeTemplateDefinition": { 
     "templateId": "_redacted_", 
     "name": "W4 3/13/2017", 
     "shared": "true", 
     "password": "", 
     "description": "", 
     "lastModified": "2017-06-05T18:45:28.4470000Z", 
     "lastModifiedBy": { 
      "userName": "Andrew", 
      "userId": "_redacted_", 
      "email": "my_email_address", 
      "uri": "https://stackoverflow.com/users/_redacted_ 
     }, 
     "pageCount": 2, 
     "uri": "/templates/_redacted_", 
     "folderName": "Templates", 
     "folderId": "_redacted_", 
     "folderUri": "/folders/_redacted_", 
     "owner": { 
      "userName": "Andrew", 
      "userId": "_redacted_", 
      "email": "my_email_address" 
     } 
    }, 
    "documents": [ 
     { 
      "documentId": "46677269", 
      "uri": "/envelopes/_redacted_/documents/46677269", 
      "name": "W4.pdf", 
      "order": "1", 
      "pages": "2", 
      "display": "inline", 
      "includeInDownload": "true", 
      "signerMustAcknowledge": "no_interaction", 
      "templateLocked": "false", 
      "templateRequired": "false", 
      "documentGroup": "content" 
     } 
    ], 
    "emailSubject": "Please DocuSign: W4.pdf", 
    "emailBlurb": "", 
    "signingLocation": "online", 
    "autoNavigation": "true", 
    "envelopeIdStamping": "true", 
    "authoritativeCopy": "false", 
    "notification": { 
     "reminders": { 
      "reminderEnabled": "false", 
      "reminderDelay": "0", 
      "reminderFrequency": "0" 
     }, 
     "expirations": { 
      "expireEnabled": "true", 
      "expireAfter": "120", 
      "expireWarn": "0" 
     } 
    }, 
    "enforceSignerVisibility": "false", 
    "enableWetSign": "true", 
    "allowMarkup": "false", 
    "allowReassign": "true", 
    "recipients": { 
     "signers": [ 
      { 
       "defaultRecipient": "false", 
       "tabs": { 
        "signHereTabs": [ 
         { 
          "stampType": "signature", 
          "name": "SignHere", 
          "tabLabel": "Signature _redacted_", 
          "scaleValue": 1.0, 
          "optional": "false", 
          "documentId": "46677269", 
          "recipientId": "94043042", 
          "pageNumber": "1", 
          "xPosition": "193", 
          "yPosition": "682", 
          "tabId": "_redacted_", 
          "templateLocked": "false", 
          "templateRequired": "false" 
         } 
        ], 
        "dateSignedTabs": [ 
         { 
          "name": "DateSigned", 
          "value": "", 
          "tabLabel": "Date Signed _redacted_", 
          "font": "lucidaconsole", 
          "fontColor": "black", 
          "fontSize": "size9", 
          "documentId": "46677269", 
          "recipientId": "94043042", 
          "pageNumber": "1", 
          "xPosition": "480", 
          "yPosition": "713", 
          "tabId": "_redacted_", 
          "templateLocked": "false", 
          "templateRequired": "false" 
         } 
        ], 
        "ssnTabs": [ 
         { 
          "validationPattern": "", 
          "validationMessage": "", 
          "shared": "false", 
          "requireInitialOnSharedChange": "false", 
          "requireAll": "false", 
          "value": "", 
          "width": 144, 
          "required": "true", 
          "locked": "false", 
          "concealValueOnDocument": "true", 
          "disableAutoSize": "false", 
          "maxLength": 4000, 
          "tabLabel": "Text _redacted_", 
          "font": "lucidaconsole", 
          "fontColor": "black", 
          "fontSize": "size9", 
          "documentId": "46677269", 
          "recipientId": "94043042", 
          "pageNumber": "1", 
          "xPosition": "442", 
          "yPosition": "563", 
          "tabId": "_redacted_", 
          "templateLocked": "false", 
          "templateRequired": "false" 
         } 
        ] 
       }, 
       "signInEachLocation": "false", 
       "name": "", 
       "email": "", 
       "recipientId": "94043042", 
       "accessCode": "", 
       "requireIdLookup": "false", 
       "routingOrder": "1", 
       "note": "", 
       "roleName": "New Employee", 
       "deliveryMethod": "email", 
       "templateLocked": "false", 
       "templateRequired": "false", 
       "inheritEmailNotificationConfiguration": "false" 
      } 
     ], 
     "agents": [ ], 
     "editors": [ ], 
     "intermediaries": [ ], 
     "carbonCopies": [ ], 
     "certifiedDeliveries": [ ], 
     "inPersonSigners": [ ], 
     "recipientCount": "1" 
    } 
} 

我想要做的就是這個模板應用到一個已經部分填寫,這樣當簽名者得到的它在定義選項卡的PDF服務器模板用於sining。

現在看來,沒有什麼。只是部分填寫的PDF,我在下面作爲base64數據傳入,沒有任何服務器模板標籤填寫或簽名。這是我的JSON API調用(在PHP中)。

$data = array (
     "emailBlurb" => "Test Email Body", 
     "emailSubject" => "Test Email Subject", 
     "status" => "sent", 
     "compositeTemplates" => array(array(
      "document" => array(
       "documentId" => 46677269, 
       "name" => $documentName, 
       "documentBase64" => $document 
      ), 
      "serverTemplates" => array(array(

       "sequence" => 1, 
       "templateId" => "_redacted_" 
      )), 
      "inlineTemplates" => array(array(
       "sequence" => 2, 
       "recipients" => array(
        "signers" => array(array(
         "email" => $recipientEmail, 
         "name" => $recipientName, 
         "recipientId" => $recipientID, 
         "roleName" => "New Employee" 
        )) 
       ) 
      )) 
     )) 
); //$data = array... 

我懷疑我只是缺少一些適當的引用到服務器模板中定義的選項卡。但是文檔非常殘酷,我已經花了幾個小時來梳理網絡。任何幫助將非常感激。

UPDATE1

按照要求,這裏的生成成功的包絡的代碼:

function c_requestSignature($templateID, $recipientName, $recipientEmail, $recipientID, $document){ 
    //function sets up the passed document for signing using the specified template 
    $documentName = "W4"; //FIXME fetch document name using templateID 
    $baseURL = c_docusignBaseURL(); 
    $accountId = c_docusignAccountId(); 
    $header = c_docusignHeader(); 
    $data = array (
     "emailSubject" => "Please sign " . $documentName, 
     //"emailBlurb" => "Test Email Body", 
     "status" => "sent", 
     "compositeTemplates" => array(
      "compositeTemplate" => array(
       "serverTemplates" => array(
        "serverTemplate" => array(
         "sequence" => "1", 
         "templateId" => "_redacted_" 
        ) 
       ), 
       "inlineTemplates" => array(
        "inlineTemplate" => array(
         "sequence" => "2", 
         "recipients" => array(
          "signers" => array(
           "signer" => array(
            "name" => $recipientName, 
            "email" => $recipientEmail, 
            "roleName" => "NewHire" 
           ) 
          ) 
         ) 
        ) 
       ), 
       "document" => array(
        "documentId" => "1", 
        "name" => $documentName, 
        "fileExtension" => "pdf", 
        "documentBase64" => $document 
       ) 
      ) 
     ) 
); 

    // Send to the /envelopes end point, which is relative to the baseUrl received above. 
    $curl = curl_init($baseURL . "/envelopes"); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json', 
    'Content-Length: ' . strlen($data_string), 
    "X-DocuSign-Authentication: $header") 
); 

    $json_response = curl_exec($curl); // Do it! 

    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
    if ($status != 201) { 
    echo "Error calling DocuSign, status is:" . $status . "\nerror text: "; 
    print_r($json_response); echo "\n"; 
    exit(-1); 
    } 

    $response = json_decode($json_response, true); 
    $envelopeId = $response["envelopeId"]; 

    error_log ("successfully created envelope: $envelopeId"); 
    $url = getSignatureURL($envelopeId, $recipientName, $recipientEmail, $recipientID); 
    return $url; 
}//c_requestSignature()... 

函數getSignatureURL()有代碼如下:

function getSignatureURL($envelopeId, $recipientName, $recipientEmail, $recipientID){ 
    //function retrieves the signing ceremony UX URL from DocuSign 
    $baseURL = c_docusignBaseURL(); 
    $accountId = c_docusignAccountId(); 
    $header = c_docusignHeader(); 
    //set up the data we'll send to the Docusign server 
    $data = array("returnUrl" => "http://_redacted_", 
    "authenticationMethod" => "none", 
    "email" => $recipientEmail, 
    "name" => $recipientName, 
    "recipientId" => $recipientID, 
    //"recipientId" => "1", 
    //"clientUserId" => $recipientID, 
    "userName" => $recipientName 
); 
    $data_string = json_encode($data); 
    //set up curl 
    $curl = curl_init($baseURL . "/envelopes/$envelopeId/views/recipient"); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json', 
    'Content-Length: ' . strlen($data_string), 
    "X-DocuSign-Authentication: $header") 
); 
    //make the API call 
    $json_response = curl_exec($curl); 
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
    if ($status != 201) { 
    echo "error calling webservice, status is:" . $status . "\nerror text is --> "; 
    print_r($json_response); echo "\n"; 
    exit(-1); 
    } 
    //retrieve and process the response 
    $response = json_decode($json_response, true); 
    return $response["url"]; 
} 

UPDATE 2

這裏的原始JSON的要求...

{ 
    "emailSubject": "some subject", 
    "status": "sent", 
    "compositeTemplates": [ 
    { 
     "serverTemplates": [ 
     { 
      "sequence": "1", 
      "templateId": "_redacted_" 
     } 
     ], 
     "inlineTemplates": [ 
     { 
      "sequence": "2", 
      "recipients": { 
      "signers": [ 
       { 
       "name": "Andrew Tester1", 
       "email": "my_email_address", 
       "roleName": "NewHire", 
       "recipientId": "1234", 
       "clientUserId": "1234" 
       } 
      ] 
      } 
     } 
     ], 
     "document": { 
     "documentId": "1", 
     "name": "W4", 
     "fileExtension": "pdf", 
     "documentBase64": "_redacted_" 
     } 
    } 
    ] 
} 

更新3

我這是阻止我看到上面的JSON的適當的輸出問題。與固定的,現在我發現了以下錯誤:

Error calling DocuSign, status is:400 error text: { "errorCode": "TAB_REFERS_TO_MISSING_DOCUMENT", "message": "The DocumentId specified in the tab element does not refer to a document in this envelope. Tab refers to DocumentId 46677269 which is not present." }

如果我更改文檔節上面如下:

 "document": { 
     "documentId": "46677269", 
     "name": "W4", 
     "fileExtension": "pdf", 
     "documentBase64": "_redacted_" 
     } 

錯誤消失,但我仍然得到了簽約儀式沒有標籤。

回答

0

以下請求可用於從服務器模板創建信封。服務器模板文檔將被替換爲請求中指定的新文檔。

{ 
    "emailSubject": "Test Email Subject", 
    "emailBlurb" : "Test Email Body", 
    "status": "sent", 
    "compositeTemplates": [ 
     { 
      "serverTemplates": [ 
       { 
        "sequence": "1", 
        "templateId": "86841739-f12d-460e-9807-23a9b90cff6b" 
       } 
      ], 
      "inlineTemplates": [ 
       { 
        "sequence": "1", 
        "recipients": { 
         "signers": [ 
          { 
           "name": "Jane Doe", 
           "email": "[email protected]", 
           "roleName": "New Employee" 
          } 
         ] 
        } 
       } 
      ],  
      "document": { 
       "documentId": "1", 
       "name": "Your Doc Name", 
       "fileExtension": "pdf", 
       "documentBase64": "" 
      } 
     }  
    ] 
} 
+0

這是否保留存在於服務器模板標籤? (即簽署的地方?)。這是我的根本問題。我需要服務器模板上的標籤保持並應用於傳入的文檔。今晚晚些時候我會試試這個,併發布結果。 – Andrew

+0

是的,它應該保留選項卡,除非新文檔的頁面數少於原始文檔且選項卡出現在截斷頁面中。 –

+0

我很難過地報告說上面的例子似乎不起作用。完全按照上面的方法實施。由此產生的PDF沒有任何標籤。 – Andrew

0

嗯,這是一個棘手的問題,但我找到了解決方案(最終),與一些幫助的形式在民間的DocuSign。我想我會在這裏爲那些未來可能遇到這個問題的人發佈它。

解決方案 傳遞給DocuSign API的json結構非常重要。如果它裏面有任何錯誤,它將無法正常工作,並且錯誤消息並不總是有幫助的。而且,在我所做的事情中,通過的具體參數也是至關重要的。上面的信封生成代碼是正確的,但需要注意的是,您必須指定屬於存儲在DocuSign服務器上模板一部分的PDF文檔ID。你可以通過API給出信封ID(這是我正在做的)來查詢它。顯然這並不是必需的,但現在它並沒有任何文件說明這一點。

雖然簽名標籤的基本問題是請求籤名儀式URL的代碼。我有額外的參數被接受,沒有錯誤,但是搞砸了。通過使用DocuSign的REST API explorer生成一個工作簽名儀式URL(包含所有正確的簽名選項卡)並比較輸出json和我試圖在代碼中傳遞的信息,發現了這一點。

下面是產生正確的JSON工作的PHP代碼:

$data = array(
    "authenticationMethod" => "email", 
    "clientUserId" => $recipientID, 
    "email" => $recipientEmail, 
    "returnUrl" => "_redacted_", 
    "userName" => $recipientName 
); 
    $data_string = json_encode($data); 
相關問題