Solved

Docusign Integration

Posted on 2014-03-25
3
560 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 108

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 108

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How can I do this in Pyhton? 12 75
.htaccess file settings 4 36
XML Data Missing in PHP SimpleXML 8 24
showing numeric numbers 2 11
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now