Php 提交表单并在DocuSign信封中预填充自定义字段

Php 提交表单并在DocuSign信封中预填充自定义字段,php,forms,docusignapi,Php,Forms,Docusignapi,由于某些原因,我无法让我的代码显示我要在左窗格中添加的自定义字段(例如,名字、姓氏等)。在提交时,我的表格应该放在信封上,并预先填充我的自定义字段。我在这里搜索了DocuSign文档和不同的线程。非常感谢您的帮助。多谢各位 <?php if(!empty($_POST)){ // Input your info: $email = "foor@bar.com"; // your account email

由于某些原因,我无法让我的代码显示我要在左窗格中添加的自定义字段(例如,名字、姓氏等)。在提交时,我的表格应该放在信封上,并预先填充我的自定义字段。我在这里搜索了DocuSign文档和不同的线程。非常感谢您的帮助。多谢各位

<?php
if(!empty($_POST)){
    // Input your info:
    $email = "foor@bar.com";                                 // your account email
    $password = "password";                              // your account password
    $integratorKey = "wouldnt-you-like-to-know"; // your account integrator key, found on (Preferences -> API page)
    $templateId = "66b7706e-936b-4438-bd5e-bd68ce47dffb";    // provide a valid templateId of a template in your account
    $templateRoleName = "Test";                              // use same role name that exists on the template in the console

    $recipientName = 'blah bleh';                        // provide a recipient (signer) name
    $recipientEmail = 'yee@haw.com';
                                                             // the recipient name and email.  Whatever you set the clientUserId to you must use the same
                                                             // value when requesting the signing URL
                                                             // construct the authentication header:
    $color = $_POST['color'];
    $number = $_POST['number'];
    $animal = $_POST['animal'];

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

    // STEP 1 - Login (retrieves baseUrl and accountId)
    $url = "https://demo.docusign.net/restapi/v2/login_information";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    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 "<br>";
        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 "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n" . "<br>";

    // STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
    $data = array(
        "accountId" => $accountId, 
        "emailSubject" => "DocuSign API - Embedded Signing Example",
        "emailBlurb" => "This is a test.",
        "compositeTemplates" => array(
            "serverTemplates" => array(
                "sequence" => "1",
                "templateId" => $templateId
            ),
            "inlineTemplates" => array(
                "sequence" => "2",
                "recipients" => array(
                    "signers" => array(
                        "roleName" => "Signer1",
                        "recipientId" => "1",
                        "name" => "John Doe",
                        "email" => "johndoe@test.com",
                        "clientUserId" => "1234",
                        "tabs" => array(
                            "textTabs" => array(
                                "tabLabel" => "address",
                                "value" => "123 Main Street"
                            )
                        )
                    )
                )
            )
        ),
        "status" => "sent"
    );    

    $data_string = json_encode($data);  
    $curl = curl_init($baseUrl . "/envelopes" );
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    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 --> <br>";
        print_r($json_response); echo "\n";
        exit(-1);
    }

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

    //--- display results   
    echo "<br>Envelope created! Envelope ID: " . $envelopeId . "\n"; 

    // STEP 3 - Get the Embedded Signing View 
    $data = array(
        "returnUrl" => "http://www.docusign.com/devcenter",
        "authenticationMethod" => "Email", 
        "clientUserId" => "1234",
        "userName" => "John Doe",
        "email" => "johnDoe@test.com"
    );   

    $data_string = json_encode($data);    
    $curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    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);
    $url = $response["url"];

    //--- display results
    echo "\n\nNavigate to this URL to start the embedded signing view of the envelope\n" . "<br>Embedded URL is: \n\n" . "<a href='$url'>HERE!</a>"; 
}
?>
<form action="" method="POST">
<label for="color">color:</label>
<input type="text" name="color">
<br>
<label for="number">number:</label>
<input type="text" name="number">
<br>
<label for="animal">animal:</label>
<input type="text" name="animal">
<br>
<button type="submit">Submit</button>
</form>    

颜色:

编号:
动物:
提交
要使用模板创建信封并在信封文档中预填充字段,需要在API请求中使用复合模板结构。(有关复合模板的信息,请参见上的“复合模板”部分。)

我不熟悉DocuSign PHP SDK,但将解释JSON中的请求语法,我想您可以找出相应的PHP语法来生成请求,如图所示

下面的示例请求(JSON)创建了一个信封,该信封使用指定的模板和一个收件人(角色名称=Signer1),并为该收件人(嵌入的签名者)预先填充值为“123 Main Street”的address字段。(虽然本例只为Signer1预填充了一个字段——但显然,您可以通过将其他字段与地址一起包含在请求的tabs对象中来预填充它们)

创建信封后(使用上述请求),将执行“POST Recipient View”请求以获取签名者1的签名URL:

(请注意,您没有在此请求中指定选项卡。)


更新#1


从您添加到原始帖子的代码开始,我已经能够对其进行修改,使其现在能够成功地创建一个信封(使用模板),其中包含一个嵌入的收件人(Signer1),并预先填充该签名者的地址文本字段。下面是代码——请注意,您需要在这个代码示例的顶部为所有变量指定值

<?php

// Set values for variables
//-----------
$email = "YOUR_DOCUSIGN_LOGIN_EMAIL";                                 // your account email
$password = "YOUR_DOCUSIGN_LOGIN_PASSWORD";                              // your account password
$integratorKey = "YOUR_DOCUSIGN_INTEGRATOR_KEY"; // your account integrator key, found on (Preferences -> API page)

$templateId = "TEMPLATE_ID";    // provide a valid templateId of a template in your account
$templateRoleName = "TEMPLATE_RECIPIENT_ROLE_NAME";                              // use same role name that exists on the template in the console

$recipientName = "SIGNER_NAME";                        // provide a recipient (signer) name
$recipientEmail = "SIGNER_EMAIL_ADDRESS";            // provide a recipient (signer) email address
$recipientId = "1";                                 // set recipient id (can be any integer value)
$clientUserId = "1234";                             // set clientUserId (can be any integer value) -- this is what makes the recipient an "embedded recipient (signer)"

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



// STEP 1 - Login (retrieves baseUrl and accountId)
//-----------
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 "\n";
    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 "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n\n";



// STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
//-----------
// tabs
$textTabs = array();
$textTabs[] = array('tabLabel' => "address", 'value' => "123 Main Street");             
$tabs = array('textTabs' => $textTabs);
#echo ("tabs:\n" . json_encode($tabs) . "\n\n");

// recipients 
$signers = array();
$signers[] = array('roleName' => $templateRoleName, 'recipientId' => $recipientId, 'name' => $recipientName, 'email' => $recipientEmail, 'clientUserId' => $clientUserId, 'tabs' => $tabs);
$recipients = array('signers' => $signers);
#echo ("recipients:\n" . json_encode($recipients) . "\n\n");

// serverTemplates
$serverTemplates = array();
$serverTemplates[] = array('sequence' => "1", 'templateId' => $templateId);
#echo ("serverTemplates:\n " . json_encode($serverTemplates) . "\n\n");

// inlineTemplates
$inlineTemplates = array();
$inlineTemplates[] = array('sequence' => "2", 'recipients' => $recipients);
#echo ("inlineTemplates:\n" . json_encode($inlineTemplates) . "\n\n");

// compositeTemplates
$compositeTemplates = array();
$compositeTemplates[] = array('serverTemplates' => $serverTemplates ,'inlineTemplates' => $inlineTemplates);
#echo ("compositeTemplates:\n" . json_encode($compositeTemplates) . "\n\n");

// request body 
$data = array('emailSubject' => "DocuSign Test - Embedded Signing", 'emailBlurb' => "Please sign. Thanks!", 'status' => 'sent', 'compositeTemplates' => $compositeTemplates);
$data_string = json_encode($data);  

$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 --> \n";
    print_r($json_response); echo "\n";
    exit(-1);
}

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

//--- display results   
echo "\nEnvelope created! Envelope ID: " . $envelopeId . "\n"; 



// STEP 3 - Get the Embedded Signing View 
//-----------
$data = array(
    "returnUrl" => "http://www.docusign.com/devcenter",
    "authenticationMethod" => "Email", 
    "clientUserId" => $clientUserId,
    "userName" => $recipientName,
    "email" => $recipientEmail
);   

$data_string = json_encode($data);    
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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);
$url = $response["url"];

//--- display results
echo "\n\nNavigate to this URL to start the embedded signing view of the envelope:\n\n" . $url . "\n\n"; 

?>


免责声明:虽然这段代码是功能性的,并且实现了目标,但这是我第一次尝试使用PHP,因此可能有更好(更高效)的方法来编写这段代码。我欢迎任何PHP专家的反馈

要使用模板创建信封并在信封文档中预填充字段,需要在API请求中使用复合模板结构。(有关复合模板的信息,请参见上的“复合模板”部分。)

我不熟悉DocuSign PHP SDK,但将解释JSON中的请求语法,我想您可以找出相应的PHP语法来生成请求,如图所示

下面的示例请求(JSON)创建了一个信封,该信封使用指定的模板和一个收件人(角色名称=Signer1),并为该收件人(嵌入的签名者)预先填充值为“123 Main Street”的address字段。(虽然本例只为Signer1预填充了一个字段——但显然,您可以通过将其他字段与地址一起包含在请求的tabs对象中来预填充它们)

创建信封后(使用上述请求),将执行“POST Recipient View”请求以获取签名者1的签名URL:

(请注意,您没有在此请求中指定选项卡。)


更新#1


从您添加到原始帖子的代码开始,我已经能够对其进行修改,使其现在能够成功地创建一个信封(使用模板),其中包含一个嵌入的收件人(Signer1),并预先填充该签名者的地址文本字段。下面是代码——请注意,您需要在这个代码示例的顶部为所有变量指定值

<?php

// Set values for variables
//-----------
$email = "YOUR_DOCUSIGN_LOGIN_EMAIL";                                 // your account email
$password = "YOUR_DOCUSIGN_LOGIN_PASSWORD";                              // your account password
$integratorKey = "YOUR_DOCUSIGN_INTEGRATOR_KEY"; // your account integrator key, found on (Preferences -> API page)

$templateId = "TEMPLATE_ID";    // provide a valid templateId of a template in your account
$templateRoleName = "TEMPLATE_RECIPIENT_ROLE_NAME";                              // use same role name that exists on the template in the console

$recipientName = "SIGNER_NAME";                        // provide a recipient (signer) name
$recipientEmail = "SIGNER_EMAIL_ADDRESS";            // provide a recipient (signer) email address
$recipientId = "1";                                 // set recipient id (can be any integer value)
$clientUserId = "1234";                             // set clientUserId (can be any integer value) -- this is what makes the recipient an "embedded recipient (signer)"

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



// STEP 1 - Login (retrieves baseUrl and accountId)
//-----------
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 "\n";
    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 "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n\n";



// STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
//-----------
// tabs
$textTabs = array();
$textTabs[] = array('tabLabel' => "address", 'value' => "123 Main Street");             
$tabs = array('textTabs' => $textTabs);
#echo ("tabs:\n" . json_encode($tabs) . "\n\n");

// recipients 
$signers = array();
$signers[] = array('roleName' => $templateRoleName, 'recipientId' => $recipientId, 'name' => $recipientName, 'email' => $recipientEmail, 'clientUserId' => $clientUserId, 'tabs' => $tabs);
$recipients = array('signers' => $signers);
#echo ("recipients:\n" . json_encode($recipients) . "\n\n");

// serverTemplates
$serverTemplates = array();
$serverTemplates[] = array('sequence' => "1", 'templateId' => $templateId);
#echo ("serverTemplates:\n " . json_encode($serverTemplates) . "\n\n");

// inlineTemplates
$inlineTemplates = array();
$inlineTemplates[] = array('sequence' => "2", 'recipients' => $recipients);
#echo ("inlineTemplates:\n" . json_encode($inlineTemplates) . "\n\n");

// compositeTemplates
$compositeTemplates = array();
$compositeTemplates[] = array('serverTemplates' => $serverTemplates ,'inlineTemplates' => $inlineTemplates);
#echo ("compositeTemplates:\n" . json_encode($compositeTemplates) . "\n\n");

// request body 
$data = array('emailSubject' => "DocuSign Test - Embedded Signing", 'emailBlurb' => "Please sign. Thanks!", 'status' => 'sent', 'compositeTemplates' => $compositeTemplates);
$data_string = json_encode($data);  

$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 --> \n";
    print_r($json_response); echo "\n";
    exit(-1);
}

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

//--- display results   
echo "\nEnvelope created! Envelope ID: " . $envelopeId . "\n"; 



// STEP 3 - Get the Embedded Signing View 
//-----------
$data = array(
    "returnUrl" => "http://www.docusign.com/devcenter",
    "authenticationMethod" => "Email", 
    "clientUserId" => $clientUserId,
    "userName" => $recipientName,
    "email" => $recipientEmail
);   

$data_string = json_encode($data);    
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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);
$url = $response["url"];

//--- display results
echo "\n\nNavigate to this URL to start the embedded signing view of the envelope:\n\n" . $url . "\n\n"; 

?>


免责声明:虽然这段代码是功能性的,并且实现了目标,但这是我第一次尝试使用PHP,因此可能有更好(更高效)的方法来编写这段代码。我欢迎任何PHP专家的反馈

我收到以下错误:{“errorCode”:“无效的请求体”,“消息”:“请求体丢失或格式不正确。无法将当前JSON对象(例如{“name\”:“value\”})反序列化到类型“System.Collections.Generic.List`1[API\u REST.Models.v2.compositeTemplate]”,因为该类型需要JSON数组(例如[1,2,3])要正确反序列化。这意味着DocuSign在指定对象的位置需要一个数组。请检查请求的完整跟踪(使用Fiddler或类似工具),并将其与我提供的示例进行比较——确保您的请求为compositeTemplates指定了一个数组(还有服务器模板、InlineTemplates等)。无法解决此问题。我已经为此困扰了几天。我最初认为,将表单中的字段放入DocuSign文档是基本的,但这非常耗时,而且他们的文档无法提供我要查找的内容的答案。如果您可以更新您的帖子/问题,并完整跟踪您当前的状态(非工作)JSON请求和返回的JSON响应,我很乐意提供关于需要更改的内容的输入,你可以使用像Fiddler这样的工具…启动Fiddler然后执行你的代码…Fiddler将向你显示JSON请求/响应。我已经安装了Fiddler,但我不太确定我在看什么,我以前从未使用过它。我无法用脚本更新我的原始问题。我必须将其作为新注释添加,我认为它不适合。我t此错误:{“errorCode”:“无效的请求正文”,“消息”:“请求正文丢失或格式不正确。无法将当前JSON对象(例如,{“name\”:“value\”})反序列化为类型“System.Collections.Generic.List`1[API\ REST.Models.v2.compositeTemplate]”,因为
<?php

// Set values for variables
//-----------
$email = "YOUR_DOCUSIGN_LOGIN_EMAIL";                                 // your account email
$password = "YOUR_DOCUSIGN_LOGIN_PASSWORD";                              // your account password
$integratorKey = "YOUR_DOCUSIGN_INTEGRATOR_KEY"; // your account integrator key, found on (Preferences -> API page)

$templateId = "TEMPLATE_ID";    // provide a valid templateId of a template in your account
$templateRoleName = "TEMPLATE_RECIPIENT_ROLE_NAME";                              // use same role name that exists on the template in the console

$recipientName = "SIGNER_NAME";                        // provide a recipient (signer) name
$recipientEmail = "SIGNER_EMAIL_ADDRESS";            // provide a recipient (signer) email address
$recipientId = "1";                                 // set recipient id (can be any integer value)
$clientUserId = "1234";                             // set clientUserId (can be any integer value) -- this is what makes the recipient an "embedded recipient (signer)"

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



// STEP 1 - Login (retrieves baseUrl and accountId)
//-----------
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 "\n";
    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 "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n\n";



// STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
//-----------
// tabs
$textTabs = array();
$textTabs[] = array('tabLabel' => "address", 'value' => "123 Main Street");             
$tabs = array('textTabs' => $textTabs);
#echo ("tabs:\n" . json_encode($tabs) . "\n\n");

// recipients 
$signers = array();
$signers[] = array('roleName' => $templateRoleName, 'recipientId' => $recipientId, 'name' => $recipientName, 'email' => $recipientEmail, 'clientUserId' => $clientUserId, 'tabs' => $tabs);
$recipients = array('signers' => $signers);
#echo ("recipients:\n" . json_encode($recipients) . "\n\n");

// serverTemplates
$serverTemplates = array();
$serverTemplates[] = array('sequence' => "1", 'templateId' => $templateId);
#echo ("serverTemplates:\n " . json_encode($serverTemplates) . "\n\n");

// inlineTemplates
$inlineTemplates = array();
$inlineTemplates[] = array('sequence' => "2", 'recipients' => $recipients);
#echo ("inlineTemplates:\n" . json_encode($inlineTemplates) . "\n\n");

// compositeTemplates
$compositeTemplates = array();
$compositeTemplates[] = array('serverTemplates' => $serverTemplates ,'inlineTemplates' => $inlineTemplates);
#echo ("compositeTemplates:\n" . json_encode($compositeTemplates) . "\n\n");

// request body 
$data = array('emailSubject' => "DocuSign Test - Embedded Signing", 'emailBlurb' => "Please sign. Thanks!", 'status' => 'sent', 'compositeTemplates' => $compositeTemplates);
$data_string = json_encode($data);  

$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 --> \n";
    print_r($json_response); echo "\n";
    exit(-1);
}

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

//--- display results   
echo "\nEnvelope created! Envelope ID: " . $envelopeId . "\n"; 



// STEP 3 - Get the Embedded Signing View 
//-----------
$data = array(
    "returnUrl" => "http://www.docusign.com/devcenter",
    "authenticationMethod" => "Email", 
    "clientUserId" => $clientUserId,
    "userName" => $recipientName,
    "email" => $recipientEmail
);   

$data_string = json_encode($data);    
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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);
$url = $response["url"];

//--- display results
echo "\n\nNavigate to this URL to start the embedded signing view of the envelope:\n\n" . $url . "\n\n"; 

?>