Simple API Client to integrate SignNow with your application or website. Sign documents, request e-signatures, and build role-based workflows with multiple signers: https://www.signnow.com/developers
- Requirements
- Install
- Setting up
- Tests
- Sandbox
- Entity manager
- Actions
- Examples & use cases
- OAuth 2.0
- Document
- Upload document
- Upload document with text tags and convert them to fillable fields
- Retrieve document
- Delete document
- Download document
- Create a single-use link for document downloading
- Create a role-based invite to sign a document
- Create a simple free form invite to sign a document
- Cancel an invite to sign a document
- Create a signing link
- Add fillable fields to a document
- Prefill fillable text fields in a document
- Template
- Document group
- Event subscriptions
- [Embedded invites] (#embedded-invites)
PHP 7.1 or newer
composer require signnow/api-php-sdk
Register an annotation loader if only there is doctrine/annotations
less v2.0 in use.
This method is deprecated and will be removed in doctrine/annotations 2.0
so
annotations will be autoloaded in 2.0.
AnnotationRegistry::registerLoader('class_exists');
Create the instance of Entity Manager:
use SignNow\Api\Service\Factory\EntityManagerFactory;
use SignNow\Api\Service\Factories\TokenFactory;
// configuring entity manager with the basic token
$entityManager =
(new EntityManagerFactory())->create(
'https://api.signnow.com',
(new TokenFactory())->basicToken('YOUR_BASIC_TOKEN_STRING')
);
use SignNow\Api\Service\Factory\EntityManagerFactory;
use SignNow\Api\Service\Factories\TokenFactory;
// configuring entity manager with the bearer token
$entityManager =
(new EntityManagerFactory())->create(
'https://api.signnow.com',
(new TokenFactory())->bearerToken('BEARER_TOKEN_STRING')
);
Setup update http method for Entity Manager:
use SignNow\Rest\Http\Request;
$entityManager->setUpdateHttpMethod(Request::METHOD_PUT);
Also, it is possible to use the wrapper using OAuth authorization
use SignNow\Api\Action\OAuth as SignNowOAuth;
$auth = new SignNowOAuth('https://api.signnow.com');
$entityManager = $auth->bearerByPassword('YOUR_BASIC_TOKEN_STRING', 'username', 'password');
SignNow PHP SDK is covered with functional tests using Codeception and Phiremock. Phiremock allows us to mock calls to SignNow API. All the calls pass at 127.0.0.1 port 8008. Ensure that this port is not in use in the local machine before running test.
Test execution in console:
vendor/bin/codecept run functional
Also, tests might be useful as examples of using SignNow PHP SDK.
Directory sandbox contains php script to taste some SDK feature. Please, provide this scripts with your personal credentials, write some code or use existing code. Execute sandbox script in console:
php sandbox/execute.php
Entity manager is the main class which controls communication with 3rd party REST API where JSON is used as main data type. It's responsible for saving objects to and fetching objects from the API.
Each entity is described by:
- API resource url (via HttpEntity annotation),
- API payload (via properties and theirs types),
- API response type (via ResponseType annotation, optional).
Upload Document to SignNow
use SignNow\Api\Entity\Document\Upload as DocumentUpload;
$uploadFile = (new DocumentUpload(new \SplFileInfo('realFilePath')));
$document = $entityManager->create($uploadFile);
Download Document from SignNow
use SignNow\Api\Entity\Document\Download as DocumentDownload;
$documentUniqueId = 'e896ec9311a74a8a8ee9faff7049446fe452e461';
$document = $entityManager->get(
new DocumentDownload(),
[
'id' => $documentUniqueId,
],
[
'type' => 'collapsed',
]);
Actions - this is just a new abstraction layer above Entity Manager and implemented as services. So that, both Entity Manager and Actions are equivalent options to use SignNow API. See actions in directory src/Action.
use SignNow\Api\Entity\Auth\TokenRequestPassword;
$entityManager->create(new TokenRequestPassword($username, $password));
use SignNow\Api\Entity\Auth\Token;
$entityManager->get(Token::class);
use SignNow\Api\Entity\Auth\TokenRequestRefresh;
$entityManager->create(new TokenRequestRefresh($refreshToken));
use SignNow\Api\Entity\Document\Upload as DocumentUpload;
$entityManager->create(new DocumentUpload(new \SplFileInfo($filePath)));
use SignNow\Api\Entity\Document\FieldExtract;
$entityManager->create(new FieldExtract(new \SplFileInfo($filePath)));
use SignNow\Api\Entity\Document\Document;
$documentUniqueId = 'e896ec9311a74a8a8ee9faff7049446fe452e461';
$entityManager->get(new Document(), ['id' => $documentUniqueId]);
use SignNow\Api\Entity\Document\Document;
$documentUniqueId = 'e896ec9311a74a8a8ee9faff7049446fe452e461';
$entityManager->delete(new Document(), ['id' => $documentUniqueId]);
use SignNow\Api\Entity\Document\Download as DocumentDownload;
$documentUniqueId = 'e896ec9311a74a8a8ee9faff7049446fe452e461';
$entityManager->get(new DocumentDownload(), ['id' => $documentUniqueId], ['type' => 'collapsed']);
// type can be 'collapsed' or 'zip'
// if need table containing the document's history set with_history=1
$entityManager->get(new DocumentDownload(), ['id' => $documentUniqueId], ['type' => 'collapsed', 'with_history' => 1]);
use SignNow\Api\Entity\Document\DownloadLink;
$documentUniqueId = 'e896ec9311a74a8a8ee9faff7049446fe452e461';
$entityManager->create(new DownloadLink(), ['id' => $documentUniqueId])
use SignNow\Api\Entity\Invite\Recipient;
use SignNow\Api\Entity\Invite\Invite;
$to[] = new Recipient($recipientEmail, $role, $roleId, $order);
$invite = new Invite($email, $to, $cc);
$entityManager->create($invite, ['documentId' => $documentUniqueId]);
use SignNow\Api\Entity\Invite\Invite;
$invite = (new Invite())
->setDocumentId($documentUniqueId)
->setTo($to)
->setFrom($from)
->setCc([])
->setSubject($subject)
->setMessage($message);
$entityManager->create($invite, ["documentId" => $documentUniqueId]);
use SignNow\Api\Entity\Invite\CancelInvite;
use SignNow\Rest\Http\Request;
$entityManager
->setUpdateHttpMethod(Request::METHOD_PUT)
->update(new CancelInvite(), ['documentId' => $documentUniqueId]);
use SignNow\Api\Entity\Invite\SigningLink;
$entityManager->create(new SigningLink($documentUniqueId));
use SignNow\Api\Entity\Document\Document;
use SignNow\Api\Entity\Document\Field\SignatureField;
use SignNow\Api\Entity\Document\Field\TextField;
$signatureField = (new SignatureField())
->setName('My Signature')
->setPageNumber(0)
->setRole('role 1')
->setRequired(true)
->setHeight(20)
->setWidth(10)
->setX(5)
->setY(10);
$textField = (new TextField())
->setName('My text')
->setLabel('Some label')
->setPrefilledText('prefilled text')
->setPageNumber(0)
->setRole('role 1')
->setRequired(true)
->setHeight(20)
->setWidth(10)
->setX(100)
->setY(150);
$document = (new Document())
->setId($documentUniqueId)
->setFields([$signatureField, $textField]);
$entityManager->update($document);
use SignNow\Api\Action\PrefillTextFields;
use SignNow\Api\Entity\Document\PrefillText\FieldRequest;
$prefill = new PrefillTextFields($bearer);
$fields = [];
$fields[] = (new FieldRequest())
->setFieldName('Document')
->setPrefilledText('Agreement #12-820/01');
$prefill->prefill($documentUniqueId, $fields);
use SignNow\Api\Entity\Template\Template;
$template = (new Template())
->setDocumentId($documentUniqueId)
->setDocumentName('My document name');
$entityManager->create($template);
use SignNow\Api\Entity\Template\Copy as TemplateCopy;
$templateCopy = (new TemplateCopy())
->setTemplateId($templateId)
->setDocumentName('My document');
$entityManager->create($templateCopy);
use SignNow\Api\Entity\DocumentGroup\DocumentGroup;
$entityManager->get(
(new DocumentGroup())
->setGroupName('my group')
->setId($documentGroupId)
->setDocuments($documentsArray)
);
use SignNow\Api\Entity\DocumentGroup\DocumentGroup;
$entityManager->delete(new DocumentGroup(), ['id' => $documentGroupId]);
use SignNow\Api\Entity\DocumentGroup\GroupInvite\Cancel as DocumentGroupInviteCancel;
$entityManager->create(
new DocumentGroupInviteCancel(),
[
'documentGroupId' => $documentGroupId,
'groupInviteId' => $groupInviteId,
]
);
use SignNow\Api\Entity\EventSubscription\GetEventSubscriptions;
$entityManager->get(new GetEventSubscriptions());
use SignNow\Api\Entity\EventSubscription\CreateEventSubscription;
$entityManager->create(
(new CreateEventSubscription())
->setEvent('document.update')
->setCallbackUrl('https://google.com.ua')
);
use SignNow\Api\Entity\EventSubscription\DeleteEventSubscription;
$entityManager->delete(
new DeleteEventSubscription(),
['uniqueId' => $uniqueId]
);
use SignNow\Api\Action\OAuth as SignNowOAuth;
use SignNow\Api\Action\EmbeddedInvite;
use SignNow\Api\Entity\Embedded\Invite\InviteRequest;
use SignNow\Api\Service\OAuth\AuthMethod\Method\None;
$auth = new SignNowOAuth('https://api.signnow.com');
$embedInvite = new EmbeddedInvite(
$auth->bearerByPassword('YOUR_BASIC_TOKEN', 'user', 'password')
);
$invites[] = (new InviteRequest())
->setEmail('name.surname@domain.com')
->setRoleId('4d4122e8574b4462a67505c0a89c6015780518f1')
->setOrder(1)
->setAuthMethod(new None())
->setFirstName('Name')
->setLastName('Surname');
$embeddedInvites = $embedInvite->create(DOCUMENT_UID, $invites);
foreach ($embeddedInvites->getInvites() as $invite) {
echo $invite->getId() , PHP_EOL,
$invite->getEmail() , PHP_EOL,
$invite->getRoleId(), PHP_EOL,
$invite->getOrder(), PHP_EOL,
$invite->getStatus(), PHP_EOL,
PHP_EOL;
}
use SignNow\Api\Action\OAuth as SignNowOAuth;
use SignNow\Api\Action\EmbeddedInvite;
$auth = new SignNowOAuth('https://api.signnow.com');
$embedInvite = new EmbeddedInvite(
$auth->bearerByPassword('YOUR_BASIC_TOKEN', 'user', 'password')
);
$documentUniqueId = '0d3122a857514462a67515c0a39c6015780518f2';
$inviteUniqueId = '3313c8fb12594004babb98a5f7418c11ad572b05';
echo $embedInvite->createSigningLink($documentUniqueId, $inviteUniqueId)->getLink();
use SignNow\Api\Action\OAuth as SignNowOAuth;
use SignNow\Api\Action\EmbeddedInvite;
$auth = new SignNowOAuth('https://api.signnow.com');
$embedInvite = new EmbeddedInvite(
$auth->bearerByPassword('YOUR_BASIC_TOKEN', 'user', 'password')
);
$expiration = 45;
$documentUniqueId = '0d3122a857514462a67515c0a39c6015780518f2';
$inviteUniqueId = '3313c8fb12594004babb98a5f7418c11ad572b05';
echo $embedInvite->setSigningLinkExpiration($documentUniqueId, $inviteUniqueId, $expiration)->getLink();
use SignNow\Api\Action\OAuth as SignNowOAuth;
use SignNow\Api\Action\EmbeddedInvite;
$auth = new SignNowOAuth('https://api.signnow.com');
$embedInvite = new EmbeddedInvite(
$auth->bearerByPassword('YOUR_BASIC_TOKEN', 'user', 'password')
);
$documentUniqueId = '0d3122a857514462a67515c0a39c6015780518f2';
$embedInvite->delete($documentUniqueId);