The Official DocuSign PHP Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
Clone or download
gsnavin Merge pull request #61 from Ohda/fix-testConfig
Delete duplicated file testConfig.php
Latest commit 9ffa9ff Jun 8, 2018

The Official DocuSign PHP Client

Build status

You can sign up for a free developer sandbox.


PHP 5.4+ or higher [].



You can install the bindings via Composer. Run the following command:

composer require docusign/esign-client

To use the bindings, use Composer's autoload:


Manual Install

If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the init.php file.



This client has the following external dependencies:


To login and send a signature request from a template:



class DocuSignSample
    public function signatureRequestFromTemplate()
        $username = "[EMAIL]";
        $password = "[PASSWORD]";
        $integrator_key = "[INTEGRATOR_KEY]";     

        // change to production ( before going live
        $host = "";

        // create configuration object and configure custom auth header
        $config = new DocuSign\eSign\Configuration();
        $config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $integrator_key . "\"}");

        // instantiate a new docusign api client
        $apiClient = new DocuSign\eSign\ApiClient($config);
        $accountId = null;
            //*** STEP 1 - Login API: get first Account ID and baseURL
            $authenticationApi = new DocuSign\eSign\Api\AuthenticationApi($apiClient);
            $options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
            $loginInformation = $authenticationApi->login($options);
            if(isset($loginInformation) && count($loginInformation) > 0)
                $loginAccount = $loginInformation->getLoginAccounts()[0];
                $host = $loginAccount->getBaseUrl();
                $host = explode("/v2",$host);
                $host = $host[0];
                // UPDATE configuration object
                // instantiate a NEW docusign api client (that has the correct baseUrl/host)
                $apiClient = new DocuSign\eSign\ApiClient($config);
                    $accountId = $loginAccount->getAccountId();
                        //*** STEP 2 - Signature Request from a Template
                        // create envelope call is available in the EnvelopesApi
                        $envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
                        // assign recipient to template role by setting name, email, and role name.  Note that the
                        // template role name must match the placeholder role name saved in your account template.
                        $templateRole = new  DocuSign\eSign\Model\TemplateRole();

                        // instantiate a new envelope object and configure settings
                        $envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
                        $envelop_definition->setEmailSubject("[DocuSign PHP SDK] - Signature Request Sample");
                        // set envelope status to "sent" to immediately send the signature request

                        // optional envelope parameters
                        $options = new \DocuSign\eSign\Api\EnvelopesApi\CreateEnvelopeOptions();

                        // create and send the envelope (aka signature request)
                        $envelop_summary = $envelopeApi->createEnvelope($accountId, $envelop_definition, $options);
                            echo "$envelop_summary";
        catch (DocuSign\eSign\ApiException $ex)
            echo "Exception: " . $ex->getMessage() . "\n";


See UnitTests.php for more examples.


Service Integrations that use Legacy Header Authentication

(Legacy Header Authentication uses the X-DocuSign-Authentication header.)

  1. Use the Authentication: login method to retrieve the account number and the baseUrl for the account. The url for the login method is for production and for the developer sandbox. The baseUrl field is part of the loginAccount object. See the docs and the loginAccount object
  2. The baseUrl for the selected account, in production, will start with na1, na2, na3, eu1, or something else. Use the baseUrl that is returned to create the basePath (see the next step.) Use the basePath for all of your subsequent API calls.
  3. As returned by login method, the baseUrl includes the API version and account id. Split the string to obtain the basePath, just the server name and api name. Eg, you will receive You want just
  4. Instantiate the SDK using the basePath. Eg ApiClient apiClient = new ApiClient(basePath);
  5. Set the authentication header as shown in the examples by using Configuration.Default.AddDefaultHeader

User Applications that use OAuth Authentication

  1. After obtaining a Bearer token, call the OAuth: Userinfo method. Obtain the selected account's base_uri (server name) field. The url for the Userinfo method is for the demo/developer environment, and for the production environment.
  2. Combine the base_uri with "/restapi" to create the basePath. The base_uri will start with na1, na2, na3, eu1, or something else. Use the basePath for your subsequent API calls.
  3. Instantiate the SDK using the basePath. Eg ApiClient apiClient = new ApiClient(basePath);
  4. Create the authentication_value by combining the token_type and access_token fields you receive from either an Authorization Code Grant or Implicit Grant OAuth flow.
  5. Set the authentication header by using Configuration.Default.AddDefaultHeader('Authorization', authentication_value)


Unit tests are available in the test folder.

Follow the steps below to run the test cases

  • Rename the "TestConfig.php-sample" to "TestConfig.php"

  • Populate all the required values like the login credentials, integrator key, host, etc in TestConfig.php

  • Run the following command from the test folder

      phpunit.phar UnitTests.php


Feel free to log issues against this client through GitHub. We also have an active developer community on Stack Overflow, search the DocuSignAPI tag.


The DocuSign PHP Client is licensed under the following License.