[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Docusign Integration

Posted on 2014-03-25
3
Medium Priority
?
746 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
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…
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 …
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 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