signnow / api-php-sdk
Library to communicate with SignNow API
Installs: 66 257
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 5
Forks: 12
Open Issues: 8
Requires
- php: ^8.2
- ext-json: *
- guzzlehttp/guzzle: ^7.8.0
- symfony/dependency-injection: ^7.0
- symfony/property-access: ^7.0
- symfony/serializer: ^7.0
Requires (Dev)
- fakerphp/faker: ^1.23
- mcustiel/phiremock-server: ^1.2
- squizlabs/php_codesniffer: ^3.7
This package is not auto-updated.
Last update: 2024-12-03 15:33:29 UTC
README
v3.0.0
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 git@github.com: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.