eristic
eristic

Reputation: 5

Docusign - Send an email to embedded signer

I'm using the embedded Docusign API to embed a document for signing. I store first name, last name, and email in a SESSION from the form before. I've tried to change the email in templateRoles to be the email that is stored in the SESSION from the form, but I either time out or get an error that the email is not the correct:

"templateRoles" => array(
      array( "roleName" => $templateRoleName, "email" => $email, "name" => $recipientName, "clientUserId" => $clientUserId )),

I'm using PHP. Any help is appreciated. I need to send an email to the embedded signer with the completed form, if it is even possible, once the signing is complete.

Thanks!

EDIT Full Call

session_start();
$results = array();
foreach($_SESSION['forms'] as $row){
$results[] = $row;
}

 $first_name = $results[0];
 $last_name = $results[1];
 $email2 = $results[2];

/////////////////////////////////////////////////////////////////////////////////////////////////
  // STEP 1 - Login (retrieves baseUrl and accountId)
  /////////////////////////////////////////////////////////////////////////////////////////////////
  $url = "https://www.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 (condition 1) webservice, status is:" . $status;
    exit(-1);
  }

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


      /////////////////////////////////////////////////////////////////////////////////////////////////
  // STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
  /////////////////////////////////////////////////////////////////////////////////////////////////
  $data = array("accountId" => $accountId,
    "emailSubject" => "Document",
            "templateId" => $templateId,
    "templateRoles" => array(
      array( "roleName" => $templateRoleName, "email" => $email2, "name" => $recipientName, "clientUserId" => $clientUserId )),
    "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 (condition 2) webservice, status is:" . $status . "<br>\nerror text is --> ";
    print_r($json_response); echo "<br>\n";
    exit(-1);
  }
      $headers = curl_getinfo($curl, CURLINFO_HEADER_OUT);
  $response = json_decode($json_response, true);
  $envelopeId = $response["envelopeId"];
  curl_close($curl);



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

      $data_string = json_encode($data);
      $curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );

      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 (condition 3), status is:" . $status . "\nerror text is --> ";
        print_r($json_response); echo "\n";
        exit(-1);
      }
              $headers = curl_getinfo($curl, CURLINFO_HEADER_OUT);
      $response = json_decode($json_response, true);
      $url = $response["url"];

               if ( $detect->isMobile() ) {
              echo "<p style='color:white;'>Click to Sign the Consent Form on your mobile device:</p>";
              echo "<a href='$url' style='width:100%; padding: 10px 20px; border: 3px solid white; color: white;'>Sign eConsent Form</a>";

                } else {
                   echo "<iframe src='$url' style='width:100%; height:100%; min-height: 800px;overflow:scroll;'></iframe>";
                }    

The authorization is in another file with templateID, email and password, clientID, etc.

Upvotes: 0

Views: 332

Answers (1)

Andrew
Andrew

Reputation: 4441

You'll want to enable a setting on your account when you log in as the administrator.

Preferences > Features > Use Envelope Complete Email for (non-suppressed) Embedded Signers

enter image description here

Upvotes: 1

Related Questions