PHP SDK setup and configuration
Learn about Quickstart and how you can use it to quickly set up and run eSignature REST API code examples.
Adding the SDK to your project
The PHP eSignature SDK is provided as a Composer package named docusign/esign-client. By default, you will always get the latest stable version of the SDK. Prerelease versions (either release candidate (RC) or beta) can also be downloaded, as shown below.
There are two ways to add the package to your project: via the command line or by downloading the SDK from GitHub.
Adding the SDK to your project using the command line
- From the command line, run:
composer require docusign/esign-client - To use the package automatically, add to Composer’s
Autoloadfile:require_once('vendor/autoload.php');
Downloading the SDK from the GitHub repository
This open-source SDK is available for download in cases where you would like to make changes to the SDK. You can download the SDK from GitHub using the instructions below:
-
Download or clone the SDK from the docusign-esign-php-client repository.
-
Bind the PHP SDK to your server or place it in a static location.
- To bind to your server, in your init.php file, add:
require_once('/path/to/docusign-esign-client/autoload.php'); - To bind to single files, in your PHP file that will utilize the PHP SDK, add:
require_once('/path/to/docusign-esign-client/autoload.php');
- To bind to your server, in your init.php file, add:
Note: If you are using Composer V2 and get the error namespace cannot be found, add the following class mapping in the composer.json file:
"autoload": { "classmap": [ "/path/to/docusign-esign-client/src" ] }
Both of the methods listed above will automatically install the latest stable version. If desired, you can specify a version. For example, you can specify version 6.0.0 of the PHP SDK by doing the following:
- Update the entry for the SDK in the
requiresection of your project’s composer.json file:"docusign/esign-client": "^6.0.0", - From the command line, run:
composer update
Including the SDK library
Once you have added the PHP SDK to your project, you will need to access the public classes that you will use. These are the principal top-level namespaces in the PHP eSignature SDK:
Docusign\eSign\Api classes
These PHP SDK classes contain endpoint categories. Each of these classes corresponds to one of the categories listed in the left menu of the eSignature REST API reference. You will need to use these classes to make calls to the public methods that initiate REST API calls to the eSignature REST API.
Note: Hereafter in the SDK documentation, the term “API object” will refer to eSignature REST API reference objects.
An API category contains all of the methods for each API resource in that category. For example, the PHP SDK EnvelopesApi class includes the createEnvelope method. This method corresponds to the Envelopes:create method of the API Envelopes resource.
The SDK’s method names roughly correspond to the API Resource: method names. The API Reference page for each endpoint lists the corresponding SDK method associated with that endpoint.
To find the PHP SDK method that corresponds to an API Resource:method page, use the API Reference page’s SDK Method box. The PHP method name will roughly correspond to the API’s SDK Method. For example, the API SDK Method Envelopes::createEnvelope is the PHP SDK method createEnvelope.
Docusign\eSign\Model classes
This namespace contains data structures and methods used to send and receive data from the eSignature API endpoints. By using these classes instead of generic JSON objects, we make PHP development with the eSignature API easier and faster than using JSON directly.
There’s a one-to-one correspondence between the objects described in the API Reference and the classes in the Docusign\eSign\Model namespace. The API object names use camelCase (the first letter is lowercase) while the corresponding SDK models use PascalCase (the first letter is uppercase). For example, the API object paymentGatewayAccounts corresponds to the PHP object PaymentGatewayAccount.
Note: The API object name is not necessarily the same as the corresponding model in the PHP SDK.
Object attribute names in the API also use camelCase. The corresponding properties of the PHP SDK are in PascalCase.
Some API endpoints also use HTTP query parameters. Within the API, the query parameters use “snake_case.” For example, the Envelopes:create API method includes an optional query parameter, change_routing_order. Within the SDK, the API’s query parameters are added as an elective options parameter after the request object.
Example: The createEnvelope method signature is:
public function createEnvelope($account_id, $envelope_definition = null, \Docusign\eSign\Api\EnvelopesApi\CreateEnvelopeOptions $options = null)
The CreateEnvelopeOptions class is used to set the API method’s query parameters. The class is defined as:
The class attributes in camelCase correspond to the API endpoint’s query parameters. The cdse_mode and completed_documents_only parameters are reserved for Docusign internal use only. More details can be found on the Query parameters section within our API reference for the createEnvelopes method. The other methods change_routing_order and merge_roles_on_draft take boolean strings (“true” or “false”) and can be configured as such:
Docusign\eSign\Client classes
This namespace contains the classes needed to manage the overall API experience. These include the classes needed to instantiate a client element to make API calls and the classes used for authentication and exception handling. You will need to include this namespace to be able to use the Docusign eSignature API correctly.
Using the SDK
To make eSignature REST API calls with the SDK, you will need:
- A current access token.
- The base path for the API call.
- For most API calls, you’ll also need the relevant
account_id. Note that it is common for a user to be a member of multiple accounts.