如何使用docusign PHP restapi创建标记

如何使用docusign PHP restapi创建标记,php,rest,docusignapi,Php,Rest,Docusignapi,我可以使用docusign登录并发送文档进行签名,但这是使用网站UI创建标记,如何通过RESTAPI动态创建标记,实际上我将使用数据库查询在循环中创建标记。 这是curret代码 ` //构造身份验证头: $header=”“$电子邮件。"" . $密码。"" . $积分器键。""; ///////////////////////////////////////////////////////////////////////////////////////////////// //步骤1-登录(

我可以使用docusign登录并发送文档进行签名,但这是使用网站UI创建标记,如何通过RESTAPI动态创建标记,实际上我将使用数据库查询在循环中创建标记。 这是curret代码

`
//构造身份验证头:
$header=”“$电子邮件。"" . $密码。"" . $积分器键。"";
/////////////////////////////////////////////////////////////////////////////////////////////////
//步骤1-登录(检索baseUrl和accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url=”https://demo.docusign.net/restapi/v2/login_information";
$curl=curl\u init($url);
curl_setopt($curl,CURLOPT_头,false);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_HTTPHEADER,数组(“X-DocuSign-Authentication:$header”);
$json\u response=curl\u exec($curl);
$status=curl\u getinfo($curl,CURLINFO\u HTTP\u代码);
如果($status!=200){
echo“调用webservice时出错,状态为:.$status;
出口(-1);
}
$response=json\u decode($json\u response,true);
$accountId=$response[“loginAccounts”][0][“accountId”];
$baseUrl=$response[“loginAccounts”][0][“baseUrl”];
curl_close($curl);
//---显示结果
echo“\naccountId=”$帐号。“\nbaseUrl=”$baseUrl。“\n”;
/////////////////////////////////////////////////////////////////////////////////////////////////
//步骤2-使用一个模板角色(称为“Signer1”)和一个收件人创建和封装
/////////////////////////////////////////////////////////////////////////////////////////////////
$data=数组(“accountId”=>$accountId,
“emailSubject”=>“DocuSign API-来自模板的签名请求”,
“templateId”=>$templateId,
“templateRoles”=>数组(
数组(“email”=>$email,“name”=>$recipientName,“roleName”=>$templateRoleName,
“tabStatuses”=>数组(
“tabStatus”=>数组(
0=>数组(
“tabLabel”=>“lic_num”,
“tabValue”=>“1111”
),
1=>数组(
“tabLabel”=>“ubi_num”,
“tabValue”=>“2222”
),
2=>数组(
“tabLabel”=>“trau nam”,
“tabValue”=>“片状”
)
)
),
“制表符”=>数组(
“textTabs”=>数组(
排列(
“tabLabel”=>“业务”,
“名称”=>“地址”,
“值”=>“来自数据库的地址”,
“show”=>“true”,
“页码”=>“1”,
“documentId”=>“1”,
“yPosition”=>“300”,
“xPosition”=>“300”,
“锁定”=>错误
)
)
)
)
),
“状态”=>“已发送”);
$data\u string=json\u 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,数组(
'内容类型:application/json',
“内容长度:”.strlen($data_string),
“X-DocuSign-Authentication:$header”)
);
$json\u response=curl\u exec($curl);
$status=curl\u getinfo($curl,CURLINFO\u HTTP\u代码);
如果($status!=201){
echo“调用Web服务时出错,状态为:“.$status”。\n错误文本为-->”;
打印($json\U响应);回显“\n”;
出口(-1);
}
$response=json\u decode($json\u response,true);
$envelopeId=$response[“envelopeId”];
//---显示结果
echo“文件已发送!信封ID=”$信封。“\n\n”;

?>`

您使用的示例利用了模板(标记是预先创建的),而您可以使用复合模板。最简单的开始就是上载文档字节并手动指定标记。以下是如何做到这一点的示例:



@SuperBiasedMan您现在看到代码了吗?谢谢,实际上我在回答之前已经完成了,但后来由于一些更改,我使用了
/templates
,所以没有使用
/envelopes
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"; 
<?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"; 
?>