sign.ytDocs

SDKs

PHP and other languages

An official PHP SDK is planned. Until then the API works with any HTTP client: it is HTTPS, Bearer authentication and JSON, plus multipart for PDF uploads.

Generated clients#

Download openapi.json and generate a client with your usual OpenAPI generator. Two endpoints take a JSON string inside a multipart form (POST /documents and POST /templates), so the shape of their payload part is documented in the Quickstart rather than in the spec.

PHP with ext-curl#

send.php
<?php
// php send.php nda.pdf [email protected] "Anna Nowak"
$key = getenv('SIGNYT_API_KEY');
$base = 'https://api.sign.yt/v1';

function signyt(string $method, string $path, $body = null, array $headers = []): array {
    global $key, $base;
    $ch = curl_init($base . $path);
    $h = array_merge(["Authorization: Bearer $key", 'Accept: application/json'], $headers);
    if (is_array($body) && !isset($body['pdf'])) {
        $body = json_encode($body);
        $h[] = 'Content-Type: application/json';
    }
    curl_setopt_array($ch, [
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => $h,
        CURLOPT_POSTFIELDS => $body,
    ]);
    $raw = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    curl_close($ch);
    $data = json_decode($raw ?: 'null', true);
    if ($status >= 400) {
        throw new RuntimeException("$status {$data['code']}: {$data['message']} (request {$data['request_id']})");
    }
    return $data ?? [];
}

[$_, $file, $email, $name] = $argv;

// 1. Draft with one signer (multipart: payload JSON + pdf file)
$doc = signyt('POST', '/documents', [
    'payload' => json_encode([
        'title' => 'Mutual NDA',
        'verification_type' => 'EMAIL_OTP',
        'recipients' => [['email' => $email, 'name' => $name, 'role' => 'SIGNER']],
    ]),
    'pdf' => new CURLFile($file, 'application/pdf', basename($file)),
]);

// 2. Signature field for that signer (percent of the page, from top-left)
signyt('PUT', "/documents/{$doc['id']}/fields", ['fields' => [[
    'type' => 'SIGNATURE', 'page' => 1, 'position_x' => 12, 'position_y' => 78,
    'width' => 28, 'height' => 7, 'recipient_id' => $doc['recipients'][0]['id'],
]]]);

// 3. Send, safe to retry thanks to the idempotency key
$sent = signyt('POST', "/documents/{$doc['id']}/send", null, ["Idempotency-Key: send-{$doc['id']}"]);
echo $sent['id'] . ' ' . $sent['status'] . PHP_EOL;

PHP with Guzzle#

<?php
// composer require guzzlehttp/guzzle
require 'vendor/autoload.php';

$http = new GuzzleHttp\Client([
    'base_uri' => 'https://api.sign.yt/v1/',
    'headers' => ['Authorization' => 'Bearer ' . getenv('SIGNYT_API_KEY')],
]);

$docs = json_decode($http->get('documents', ['query' => ['limit' => 10]])->getBody(), true);
foreach ($docs as $d) {
    echo "{$d['id']} {$d['status']} {$d['title']}\n";
}

$pdf = $http->get("documents/{$docs[0]['id']}/signed.pdf")->getBody();
file_put_contents('signed.pdf', $pdf);

Webhooks in PHP#

Verify signatures with hash_hmac and hash_equals; see the PHP tab in Verify signatures.