簡體   English   中英

如何使用docusign PHP REST API創建標簽

[英]How to create Tags using docusign PHP REST API

我可以使用docusign登錄並發送文檔進行簽名,但是那是使用網站UI創建的標簽,如何通過其REST API動態創建標簽,實際上我將與數據庫查詢一起循環創建。 這是當前代碼。

`

// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";

/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (to retrieve baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 200 ) {
    echo "error calling webservice, status is:" . $status;
    exit(-1);
}

$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);

// --- display results
echo "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";

/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create and envelope using one template role (called "Signer1") and one recipient
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("accountId" => $accountId, 
    "emailSubject" => "DocuSign API - Signature Request from Template",
    "templateId" => $templateId, 
    "templateRoles" => array( 
            array( "email" => $email, "name" => $recipientName, "roleName" => $templateRoleName, 

                "tabStatuses" => array(

                        "tabStatus" => array(
                            0 => array( 
                                "tabLabel" => "lic_num",
                                "tabValue" => "1111"
                            ),
                            1 => array( 
                                "tabLabel" => "ubi_num",
                                "tabValue" => "2222"
                            ),
                            2 => array( 
                                "tabLabel" => "tra_nam",
                                "tabValue" => "Flakey"
                            )
                         )
                     ),
                        "tabs" => array(
                            "textTabs" => array (
                                                  array (
                                                    "tabLabel"=> "business",
                                                      "name" => "address",
                                                      "value" => "Address from DB",
                                                      "show" => "true",
                                                       "pageNumber"=> "1",
                                                        "documentId"=> "1",
                                                        "yPosition"=> "300",
                                                        "xPosition"=> "300",
                                                        "locked"=> false
                                                      )
                                                )
                                    )
                )
            ),
    "status" => "sent");                                                                    

$data_string = json_encode($data);  
$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);
$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);
}

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

// --- display results
echo "Document is sent! Envelope ID = " . $envelopeId . "\n\n"; 

?>`

您正在使用的示例利用了模板(預先創建了標簽),而您可以使用復合模板,最容易開始的事情就是上傳文檔字節並手動指定標簽。 這是如何執行此操作的示例: http : //iodocs.docusign.com/APIWalkthrough/requestSignatureFromDocument

<?php

    // Input your info here:
    $email = "***";         // your account email
    $password = "***";      // your account password
    $integratorKey = "***";     // your account integrator key, found on (Preferences -> API page)
    $recipientName = "***";     // provide a recipient (signer) name
    $documentName = "***";      // copy document with same name into this directory!

    // construct the authentication header:
    $header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";

    /////////////////////////////////////////////////////////////////////////////////////////////////
    // STEP 1 - Login (to retrieve baseUrl and accountId)
    /////////////////////////////////////////////////////////////////////////////////////////////////
    $url = "https://demo.docusign.net/restapi/v2/login_information";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));

    $json_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    if ( $status != 200 ) {
        echo "error calling webservice, status is:" . $status;
        exit(-1);
    }

    $response = json_decode($json_response, true);
    $accountId = $response["loginAccounts"][0]["accountId"];
    $baseUrl = $response["loginAccounts"][0]["baseUrl"];
    curl_close($curl);

    //--- display results
    echo "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";

    /////////////////////////////////////////////////////////////////////////////////////////////////
    // STEP 2 - Create an envelope with one recipient, one tab, and one document and send
    /////////////////////////////////////////////////////////////////////////////////////////////////

    // the following request body will place 1 signature tab on the document you supply, located
    // 100 pixels to the right and 100 pixels down from the top left of the document
    $data = array (
            "emailSubject" => "DocuSign API - Signature Request on Document",
            "documents" => array( array( "documentId" => "1", "name" => $documentName)),
            "recipients" => array( "signers" => array(
                array(  "email" => $email,
                        "name" => $recipientName,
                        "recipientId" => "1",
                        "tabs" => array(
                            "signHereTabs" => array(
                                array( "xPosition" => "100",
                                       "yPosition" => "100",
                                       "documentId" => "1",
                                       "pageNumber" => "1" )
                            ))
                 ))
            ),
        "status" => "sent"
    );
    $data_string = json_encode($data);  

    $file_contents = file_get_contents($documentName);

    $requestBody = "\r\n"
    ."\r\n"
    ."--myboundary\r\n"
    ."Content-Type: application/json\r\n"
    ."Content-Disposition: form-data\r\n"
    ."\r\n"
    ."$data_string\r\n"
    ."--myboundary\r\n"
    ."Content-Type:application/pdf\r\n"
    ."Content-Disposition: file; filename=\"$documentName\"; documentid=1 \r\n"
    ."\r\n"
    ."$file_contents\r\n"
    ."--myboundary--\r\n"
    ."\r\n";

    // *** append "/envelopes" to baseUrl and as signature request endpoint
    $curl = curl_init($baseUrl . "/envelopes" );
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);                                                                  
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: multipart/form-data;boundary=myboundary',
        'Content-Length: ' . strlen($requestBody),
        "X-DocuSign-Authentication: $header" )                                                                       
    );

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

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

    //--- display results
    echo "Document is sent! Envelope ID = " . $envelopeId . "\n\n"; 
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM