Skip to content

The Official SignNow PHP SDK library for interacting with SignNow REST API. Sign documents, request e-signatures, and build role-based workflows with multiple signers using this client.

License

Notifications You must be signed in to change notification settings

signnow/SignNowPHPSDK

Repository files navigation

signNow API PHP SDK

v3.0.0

PHP Version

Requirements

  • PHP 8.2 or higher
  • composer
  • cURL extension

Installation

Get SDK code via composer

composer require signnow/api-php-sdk:v3

or via git

git clone [email protected]:signnow/SignNowPHPSDK.git

Install dependencies

make install

Configuration

Copy .env.example to .env and fill your credentials in the required values

cp .env.example .env

Run tests

To run tests you need to have a valid .env.test file with credentials for testing. If you don't have it, you can create it by copying the .env.test.dist file and renaming it to .env.test. However, the file will be created automatically if you just run test execution with the following commands:

## Run mock server locally
make mock-up
## Run tests
make test-run

Mock server will be available at http://0.0.0.0:8086.

Usage

To start using the SDK, you need to create a new instance of the SDK API client and authenticate it using the credentials from the .env file.

require_once __DIR__ . '/vendor/autoload.php';

use SignNow\ApiClient;
use SignNow\Api\Document\Request\DocumentGet;
use SignNow\Exception\SignNowApiException;
use SignNow\Sdk;

$sdk = new Sdk();

try {
    // Method authenticate() will use the credentials from the .env file
    // and create a new bearer token for further requests
    $apiClient = $sdk->build()
        ->authenticate()
        ->getApiClient();
    // Now, you are ready to use the API client to send requests

    // if you want to keep the token, you can use the following code
    $bearerToken = $sdk->actualBearerToken();
    // or
    $bearerToken = $apiClient->getBearerToken();
} catch (SignNowApiException $e) {
    echo $e->getMessage();
}

If you have already received a bearer token and wish to reuse it, then the following API client initialization scheme will be useful:

require_once __DIR__ . '/vendor/autoload.php';

use SignNow\ApiClient;
use SignNow\Api\Document\Request\DocumentGet;
use SignNow\Core\Token\BearerToken;
use SignNow\Exception\SignNowApiException;
use SignNow\Sdk;

$sdk = new Sdk();

try {
    $token = 'YOUR_TOKEN_HERE';
    $apiClient = $sdk->build()
        ->withBearerToken(new BearerToken($token, '', 0))
        ->getApiClient();
    // Now, you are ready to use the API client to send requests
} catch (SignNowApiException $e) {
    echo $e->getMessage();
}

Example of sending a request to get a document by id:

require_once __DIR__ . '/vendor/autoload.php';

use SignNow\ApiClient;
use SignNow\Api\Document\Request\DocumentGet;
use SignNow\Exception\SignNowApiException;
use SignNow\Sdk;

$sdk = new Sdk();

try {
    // Instantiate the API client
    $apiClient = $sdk->build()
        ->authenticate()
        ->getApiClient();

    // Prepare a request to get a document by id
    $documentId = 'e896ec9311a74a8a8ee9faff7049446fe452e461';
    $request = new DocumentGet();
    $request->withDocumentId($documentId);

    // Send the request and get the response
    $response = $apiClient->send($request);
} catch (SignNowApiException $e) {
    echo $e->getMessage();
}

Examples

You can find more examples of API usage in the examples directory.

About

The Official SignNow PHP SDK library for interacting with SignNow REST API. Sign documents, request e-signatures, and build role-based workflows with multiple signers using this client.

https://www.signnow.com/developers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages