Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Docusign Integration

Posted on 2014-03-25
3
Medium Priority
?
739 Views
Last Modified: 2014-04-02
I have the following code that pushes a .txt file to DocuSign and it works great, but I can't figure out out to populate the recipient array with the 2nd signer (line 3 and 7)?  Any help?

// Input your info here:
	$email = stripslashes($_POST[email1]);			// your account email (also where this signature request will be sent)
	$email2 = stripslashes($_POST[email2]);
        $password = "XXXX";		// your account password
	$integratorKey = "XXXX";		// your account integrator key, found on (Preferences -> API page)
	$recipientName = stripslashes($_POST[applicant_name]);		// provide a recipient (signer) name
	$recipientName2 = stripslashes($_POST[applicant_name2]);		
// provide a recipient (signer) name$documentName = "../rental_app_data/xxxxx.txt";		// copy document with same name into this directory!
	$documentName ="rental_app_data/".$app_file_name.".txt";
// 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" => "200",
                                       "yPosition" => "175",
                                       "documentId" => "1",
                                       "pageNumber" => "2" )
                            ))
                 ))
            ),
	    "status" => "sent"
	);
	$data_string = json_encode($data);  

Open in new window

0
Comment
Question by:rcowen00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39954272
Good grief - how confusing can code get?  All those nested arrays are amazingly complicated.  

First step - check the documentation to ensure that it's possible to have two signatures.
Second step - see if they have an example showing how they recommend this.

I cannot test this code and there are so many levels of nesting that it's nearly impossible to see if it's lined up correctly, but it might go something like this. Please see lines 48, et seq.

// Input your info here:
	$email = stripslashes($_POST[email1]);			// your account email (also where this signature request will be sent)
	$email2 = stripslashes($_POST[email2]);
        $password = "XXXX";		// your account password
	$integratorKey = "XXXX";		// your account integrator key, found on (Preferences -> API page)
	$recipientName = stripslashes($_POST[applicant_name]);		// provide a recipient (signer) name
	$recipientName2 = stripslashes($_POST[applicant_name2]);		
// provide a recipient (signer) name$documentName = "../rental_app_data/xxxxx.txt";		// copy document with same name into this directory!
	$documentName ="rental_app_data/".$app_file_name.".txt";
// 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"  => "200"
                      , "yPosition"  => "175"
                      , "documentId" => "1"
                      , "pageNumber" => "2" 
                      )
                    )
                  )
                )
              , array
                ( "email"       => $email2
                , "name"        => $recipientName2
                , "recipientId" => "1"
                , "tabs"        => array
                  ( "signHereTabs" => array
                    ( array
                      ( "xPosition"  => "400"
                      , "yPosition"  => "175"
                      , "documentId" => "1"
                      , "pageNumber" => "2" 
                      )
                    )
                  )
                )
                
              )
            )
            ,
	    "status" => "sent"
	)
	;
	$data_string = json_encode($data);

Open in new window

0
 

Author Comment

by:rcowen00
ID: 39954282
I have been scouring the documentation since 4am and can't find an example, but it does state it will take multiple signatures.  Thanks for the assistance, I will give that a try.  Also, glad to hear it wasn't just me:)
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39954315
Might be worth seeing if they have a tech support department or a forum for the software.  Believe me, it's not just you -- this is complicated!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question