PHP code example of tucker-eric / docusign-rest-client

1. Go to this page and download the library: Download tucker-eric/docusign-rest-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tucker-eric / docusign-rest-client example snippets




nt = new DocuSign\Rest\Client([
	'impersonated_user_id' => $impersonated_user_id,
	'integrator_key'       => $integrator_key,
	'host'                 => $host,
	'private_key'          => $private_key,
	'auth_server'          => $auth_server
]);

$client->accounts // Returns DocuSign\eSign\Api\AccountsApi

$client->customTabs // Returns DocuSign\eSign\Api\CustomTabsApi

$client->folders // Returns DocuSign\eSign\Api\FoldersApi


$client->folders->list();  // Returns \DocuSign\eSign\Model\FoldersResponse



nt = new DocuSign\Rest\Client([
            'impersonated_user_id' => $impersonated_user_id,
            'private_key'          => $private_key,
            'integrator_key'       => $integrator_key,
            'host'                 => $host,
            'auth_server'          => $auth_server
]);

$templateRole = $client->templateRole([
	'email' 	=> '[SIGNER_EMAIL]',
	'name'  	=> '[SIGNER_NAME]',
	'role_name' => '[ROLE_NAME]'
]); // Returns DocuSign\eSign\Model\TemplateRole

$templateRole->getRoleName() // returns '[ROLE_NAME]' as set in the above method.

$envelopeDefinition = $client->envelopeDefinition([
	'status'         => 'sent'
	'email_subject'  => '[DocuSign PHP SDK] - Signature Request Sample',
	'template_id'    => '[TEMPLATE_ID]',
	'template_roles' => [
		$templateRole
	],
]); // Returns DocuSign\eSign\Model\EnvelopeDefinition



$foldersApi = $this->client->folders;
$searchOptions = $foldersApi->searchOptions([
	'count'     => 20,
	'order_by'  => 'sent',
	'from_date' => '2010-01-01'
]);
$foldersApi->search($searchOptions);


$envelopesApi = $this->client->envelopes;
$envelopesApi->createEnvelopeOptions([
	'merge_roles_on_draft' => 'true'
]);
$envelopesApi->updateOptions([
	'resend_envelope' => 'true'
]);

$envelopesApi->getOptions(); // returns ['updateOptions' => DocuSign\eSign\Api\EnvelopesApi\UpdateOptions, 'createEnvelopeOptions' => DocuSign\eSign\Api\EnvelopesApi\CreateEnvelopeOptions]

$envelopesApi->getOptions('updateOptions') // returns DocuSign\eSign\Api\EnvelopesApi\UpdateOptions




 DocuSignSample
{
	public function signatureRequestFromTemplate()
	{

	    $impersonated_user_id = "[IMPERSONATED_USER_ID]";
        $private_key = "[PRIVATE_KEY]";
        $integrator_key = "[INTEGRATOR_KEY]";

		// change these to production before going live
        $host = "https://demo.docusign.net/restapi";
        $auth_server = "account-d.docusign.com";
		// Once instantiated, authentication is handled automatically
        $client = new DocuSign\Rest\Client([
            'impersonated_user_id' => $impersonated_user_id,
            'private_key'          => $private_key,
            'integrator_key'       => $integrator_key,
            'host'                 => $host,
            'auth_server'          => $auth_server
        ]);

    	$templateRole = $client->templateRole([
			'email' 	=> '[SIGNER_EMAIL]',
			'name'  	=> '[SIGNER_NAME]',
			'role_name' => '[ROLE_NAME]'
    	]);

    	$envelopeDefinition = $client->envelopeDefinition([
    		'status'         => 'sent',
    		'email_subject'  => '[DocuSign PHP SDK] - Signature Request Sample',
    		'template_id'    => '[TEMPLATE_ID]',
    		'template_roles' => [
    			$templateRole
    		],
    	]);
		
    	$envelopeOptions = $client->envelopes->createEnvelopeOptions([			
			'merge_roles_on_draft' => false
    	]);
		
    	$envelopeSummary = $client->envelopes->createEnvelope($envelopeDefinition, $envelopeOptions);
	}
}



 DocuSignSample
{

	protected $impersonated_user_id = "[IMPERSONATED_USER_ID]";
    protected $private_key = "[PRIVATE_KEY]";
    protected $integrator_key = "[INTEGRATOR_KEY]";

	// change these to production before going live
    protected $host = "https://demo.docusign.net/restapi";
    protected $auth_server = "account-d.docusign.com";

    protected $client;

	public function __construct()
	{
		// Once instantiated, authentication is handled automatically
        $this->client = new DocuSign\Rest\Client([
            'impersonated_user_id' => $impersonated_user_id,
            'private_key'          => $private_key,
            'integrator_key'       => $integrator_key,
            'host'                 => $host,
            'auth_server'          => $auth_server
        ]);
	}
	
	/**     
     * @return DocuSign\eSign\Model\EnvelopeSummary
     */
	public function signatureRequestFromTemplate()
	{
    	return $this->client->envelopes->createEnvelope($this->client->envelopeDefinition([
	    		'status'         => 'sent',
	    		'email_subject'  => '[DocuSign PHP SDK] - Signature Request Sample',
	    		'template_id'    => '[TEMPLATE_ID]',
	    		'template_roles' => [
	    			$this->client->templateRole([
						'email' 	=> '[SIGNER_EMAIL]',
						'name'  	=> '[SIGNER_NAME]',
						'role_name' => '[ROLE_NAME]'
			    	])
	    		]
	    	])
    	);
	}
}