Back

Step by Step Guide to Building a SignRequest API Integration in PHP

Aug 15, 20244 minute read

Introduction

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!

Prerequisites

Before we jump in, make sure you've got:

  • A PHP environment (you're a PHP dev, so I'm sure you've got this covered)
  • Composer installed (because who wants to manage dependencies manually?)
  • SignRequest API credentials (grab these from your SignRequest account)

Installation

First things first, let's get that package installed. Fire up your terminal and run:

composer require signrequest/signrequest-php

Easy peasy, right?

Configuration

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!

Basic Usage

Creating a Document

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?

Advanced Features

Using Templates

Templates make life easier. Here's how to use one:

$document = $client->createDocument([ 'template' => 'YOUR_TEMPLATE_UUID', 'signers' => [ ['email' => '[email protected]'], ], ]);

Webhooks

Want to know when something happens? Set up a webhook:

$client->createWebhook([ 'url' => 'https://your-app.com/webhook', 'event_type' => 'document_signed', ]);

Error Handling

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(); }

Best Practices

  • Keep your API key secret (use environment variables!)
  • Respect rate limits (SignRequest is generous, but don't abuse it)
  • Use HTTPS for webhook endpoints (security first!)

Testing

Before going live, test in the sandbox environment:

$client->getConfig()->setHost('https://sandbox.signrequest.com/api/v1/');

Conclusion

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! 🚀