SB Sealed in Black Help Center
← Back to site

← All articles

Developer · 4 min read

Send a document with code

To send a document, POST a template id and the signer(s) to /esign/documents. Include an external_refyour own record id — so you can match the result back to your system later.

POST https://sealedinblack.com/api/v1/esign/documents
Authorization: Bearer YOUR_sib_KEY
Content-Type: application/json

{
  "template_id": 12,
  "signers": [{ "name": "Jane Doe", "email": "jane@example.com" }],
  "external_ref": "record_8842",
  "webhook_url": "https://your-website.com/hooks/sealedinblack"
}

Auto-filling text (merge fields). When you build a template you can drop a merge field anywhere on the page and give it a plain name like territory or cities. Then add a fields object to your send and each value is printed onto the document — before the signer opens it — right where you placed it. The signer can read it but can’t change it. This is how you send the same contract to a hundred people with each one’s own details already on the page.

{
  "template_id": 12,
  "signers": [{ "name": "Jane Doe", "email": "jane@example.com" }],
  "fields": {
    "territory": "Greater Covington Region",
    "cities": "Covington, Mandeville, Slidell"
  },
  "external_ref": "record_8842"
}

Not sure which names a template expects? Ask it: GET /esign/templates/12 lists them under merge_fields. You don’t have to match the format exactly — case and separators are ignored, so partner_name, Partner Name and partnerName all fill the same field. And the send reply includes "merge_fields": { "filled": [...], "blank": [...] } so you can immediately see if a value didn’t land (e.g. a forgotten key) instead of discovering it on the finished PDF.

You get back 201 and the document (status "sent"). Here’s a ready-to-use PHP helper — set your key as the SIB_API_KEY server setting:

<?php
function sib_send_document($templateId, $name, $email, $externalRef, $phone = null) {
    $key = getenv('SIB_API_KEY');
    $signer = ['name' => $name, 'email' => strtolower(trim($email))];
    if ($phone) $signer['phone'] = $phone;

    $payload = [
        'template_id' => $templateId,
        'signers'     => [$signer],
        'external_ref'=> $externalRef,  // your record id — comes back on the webhook
        'webhook_url' => 'https://your-website.com/hooks/sealedinblack',
    ];

    $ch = curl_init('https://sealedinblack.com/api/v1/esign/documents');
    curl_setopt_array($ch, [
        CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 20,
        CURLOPT_HTTPHEADER => ['Authorization: Bearer '.$key, 'Content-Type: application/json'],
        CURLOPT_POSTFIELDS => json_encode($payload),
    ]);
    $body = curl_exec($ch);
    $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return ['ok' => $status === 201, 'response' => json_decode($body, true)];
}

To send many, just loop your records and call it once each (space them out a little — a few per second).

Still stuck? Email support@sealedinblack.com.