如何使用docusign PHP REST API创建标签

时间:2015-07-15 09:11:12

标签: php rest docusignapi

我可以使用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"; 

&GT;`

0 个答案:

没有答案