Solved

Docusign Integration

Posted on 2014-03-25
3
640 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
  • 2
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 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 109

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

839 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