Hey there, fellow developer! Ready to dive into the world of digital signatures? Let's talk about integrating the SignRequest API into your PHP project. We'll be using the signrequest/signrequest-php
package to make our lives easier. Buckle up, and let's get coding!
Before we jump in, make sure you've got:
First things first, let's get that package installed. Fire up your terminal and run:
composer require signrequest/signrequest-php
Easy peasy, right?
Now, let's set up our API client. It's as simple as:
use SignRequest\Client; $client = new Client(); $client->getConfig()->setApiKey('YOUR_API_KEY');
Replace 'YOUR_API_KEY'
with your actual API key, and you're good to go!
Let's create a document and send it for signature:
$document = $client->createDocument([ 'file_from_url' => 'https://example.com/document.pdf', 'signers' => [ ['email' => '[email protected]'], ], ]); $client->sendSignatureRequest($document);
Boom! You've just created a document and sent it for signature. How cool is that?
Templates make life easier. Here's how to use one:
$document = $client->createDocument([ 'template' => 'YOUR_TEMPLATE_UUID', 'signers' => [ ['email' => '[email protected]'], ], ]);
Want to know when something happens? Set up a webhook:
$client->createWebhook([ 'url' => 'https://your-app.com/webhook', 'event_type' => 'document_signed', ]);
Things don't always go smoothly, so let's catch those errors:
try { // Your SignRequest API calls here } catch (\SignRequest\ApiException $e) { echo "Oops! " . $e->getMessage(); }
Before going live, test in the sandbox environment:
$client->getConfig()->setHost('https://sandbox.signrequest.com/api/v1/');
And there you have it! You're now equipped to integrate SignRequest into your PHP project. Remember, the API docs are your friend if you need more details. Now go forth and digitize those signatures!
Happy coding! 🚀