Solved

Docusign Integration

Posted on 2014-03-25
3
657 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 110

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 110

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

733 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