Working with the EchoSign API in PHP

*Note* This post will be using my in-development PHP wrapper, so you’ll need it to follow along: The core document methods in the wrapper are pretty solid and being used in production, the rest of the methods are currently untested and are not considered production ready at this point. I’m still working on implementing all the functionality so you will find some missing functionality at this point.

As I was getting used to the API, I ran into a couple gotchas, hopefully this small walk through will serve as a helpful quickstart.

Getting Started

All you really need to get the wrapper running is an API key for EchoSign’s service. You can sign up for a free developer account here: EchoSign Developer Account Signup.

Testing the Connection

require_once 'bootstrap.php';
$echosign = new EchoSignAPI('Your API key here');
$result = $echosign->ping();

In response you should see a message similar to this:

stdClass Object
    [pong] => stdClass Object
            [message] => It works!


Sending your first Document

EchoSign can take both regular PDFs and PDF forms. When you send a regular PDF file, they will automatically append a signature field to the bottom of the document. PDF forms offer significantly more functionality with their API. You can determine one (or multiple) signature locations, populate fields with specific data from EchoSign, or prepopulate custom fields with your own data. You can read about the extent of their PDF form integration here (pdf).

The following example uses demo.pdf.

    require_once 'bootstrap.php';

    $echosign_api_key = 'Your API Key';
    $to_email_address = 'Signers email address';

    //merge field data - optional
    $first_name = 'Craig';
    $last_name = 'Ballinger';
    $website_address = ''; 
    $echosign = new EchoSignAPI($echosign_api_key);
    $document = new EchoSignDocument('Demo PDF', 'demo.pdf');
    //Merge fields allow you to prepopulate pdf form fields with data
    //they are optional and can be excluded if not required
    $merge_fields = new EchoSignMergeFields();
    $merge_fields->add('first_name', $first_name);
    $merge_fields->add('last_name', $last_name);
    $merge_fields->add('website', $website_address);
    //at least one recipient is required.
    $recipients = new EchoSignRecipients;
    $package = new EchoSignDocumentPackage($document, $recipients);
        $result = $echosign->sendDocument($package);
        echo 'Success - Document Key:'. $result->documentKeys->DocumentKey->documentKey;
    }catch(Exception $e){
        echo 'An error occurred: '.$e->getMessage();