0
votes

I am using the docusign rest api. I am trying to create a template and then use embedded sending.

Here is my code:

Create a template:

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

$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 ) {
  $status = 'notok';
}

$response = json_decode($json_response, true); 

if( (isset($response['errorCode']))  && ($response['errorCode'] == 'USER_LACKS_PERMISSIONS')) {
  echo $msg = 'This user lacks sufficient permissions';
  $_SESSION['msg_frm_apd'] = $msg;

}



 $accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);

 $template_name = "template_" . time();

$data = "{
  \"emailBlurb\":\"String content\",
\"emailSubject\":\"String content\",
  \"documents\": [{
\"documentId\": \"1\",
\"name\": \"document.pdf\"
}],
\"recipients\": {
\"signers\": [{
\"recipientId\": \"1\",
\"roleName\": \"Signer 1\"
}]
},
\"envelopeTemplateDefinition\": {
\"description\": \"Description\",
\"name\": \"$template_name\"
}
}";  





$file_contents = file_get_contents("uploads/envelopes/" . $file_name);

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


$url = "https://demo.docusign.net/restapi/v2/accounts/376082/templates";


$curl = curl_init($url);
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); 
$response = json_decode($json_response, true);


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

Embedded Sending:

$templateId = $response['templateId'];   // provide a valid templateId of a template in your account

  $clientUserId = "1234"; 
  $templateRoleName = "Signer 1";

$data = array("accountId" => $accountId, 
    "emailSubject" => "DocuSign API - Embedded Sending Example",
    "templateId" => $templateId, 
    "templateRoles" => array(
      array( "roleName" => $templateRoleName, "email" => $recipient_email, "name" => $recipient_name, "clientUserId" => $clientUserId )),
    "status" => "created");                                                                    



  $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" )                                                                docusign       
  );

  $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"];
  curl_close($curl);

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

  /////////////////////////////////////////////////////////////////////////////////////////////////
  // STEP 3 - Get the Embedded Sending View (aka the "tag-and-send" view)
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /*$data = array("returnUrl" => "http://www.docusign.com/devcenter");*/
  $returnUrl = $SITE_URL . "/docusign_return.php";
  $data = array("returnUrl" => $returnUrl);                                                                    
  $data_string = json_encode($data);                                                                                   
  $curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/sender" );
  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);
  $response = json_decode($json_response, true);
  $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);
  }

  $url = urlencode($response["url"]);

When i click on the above url, i am getting a page where i can tag and send the document. There is an email address field in this page which is automatically populated with the $recipient_email. But the problem is that the mail is not going to the recipient email address. Thanks.(also i am not getting any error messages).

2

2 Answers

1
votes

There is no problem with your code and it is working perfectly as expected. I can tell that you are using DocuSign's sample code from their API Walkthroughs.

If you're saying everything is working ok and no errors, but that after navigating to the embedded sending URL and sending the document for signature the recipient is not receiving the email I would check for things like security software, spam/junk mail filters, firewalls, etc on your side. The DocuSign service is so widely used that if the emails weren't going out in signature requests there would be a big stink about it pretty quickly, and on top of that I just did a test and my emails are going out just fine.

So as mentioned, if you're sure the email address is correct and you are hitting the SEND button through the UI, I'd check security software, spam/junk mail filters, firewalls, and anything else that might stop the email from arriving on your side.

1
votes

Another suggestion for troubleshooting issues with email delivery: use DocuSign Connect. If your account is configured properly, you could enable Connect and use the Connect logs to detect if the recipient email is undeliverable (i.e., if DocuSign's receiving a 'bounce-back' when sending to that address).

  • Create a Custom Connect Configuration in DocuSign, as described in this guide: http://www.docusign.com/sites/default/files/DocuSign_Connect_Service_Guide.pdf.

  • In the Connect Configuration that you create, you can specify any URL as the URL to publish to -- all you're trying to do for this test is to make Connect send the notification for the "Recipient Sent" event and "Recipient Delivery Failed" event (and create Log entries for the notifications it sends) -- it doesn't matter that the endpoint you specify won't be equipped to receive/process the Connect message.

  • In the Connect Configuration that you create, be sure to select the options I've highlighted here (as previously stated, you can use any URL -- I just happened to have chosen google.com): Connect Configuration settings

  • Once you've created and saved the Connect Configuration as described above, go through the process you describe in your question to create/send the Envelope.

  • Once you've sent the Envelope, login to the DocuSign web console (as Administrator), and view the Connect log entries. (i.e., navigate to Preferences >> Connect >> Logs Connect Logs link

  • You should see log entries listed for each "Recipient Sent" and/or "Recipient Delivery Failed" event that's occurred since the time that you created/enabled the Connect Configuration. Connect log entries

  • Examining the contents of the log entries should allow you to determine if DocuSign is successfully sending the Recipient email(s), and also whether the Recipient email(s) are bouncing back as undeliverable.

If the log entries indicate that DocuSign is sending the Recipient email(s) and do NOT indicate any bounce-backs, then it's likely an issue with the Email client that's preventing the recipient from receiving the email(s) (as Ergin suggested in his answer).