Undersign
v1.1
Create Free Account
API Reference SDKs & Examples · PHP
SDKs & Examples

PHP Examples

Call the Undersign API from server-side PHP. Keep tokens in environment variables and inspect the JSON response.

Credentials

Store your token in an environment variable, never in code:

Shell
UNDERSIGN_API_TOKEN=<BEARER_TOKEN>

List templates

PHP
$ch = curl_init("https://toolkit.undersign.app/api/v1.1/templates");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer " . getenv('UNDERSIGN_API_TOKEN')
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);

Create a signature request

PHP
$payload = [
    "mode"    => "email",
    "message" => "Please sign the official documents.",
    "templates" => [
        [
            "template_id" => "<template-uuid>",
            "signers" => [
                ["name" => "John Doe", "email" => "<signer-email-1>"]
            ]
        ]
    ]
];

$ch = curl_init("https://toolkit.undersign.app/api/v1.1/signature-requests");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer " . getenv('UNDERSIGN_API_TOKEN'),
    "Content-Type: application/json",
    "Idempotency-Key: " . bin2hex(random_bytes(16))
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));

$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);

if (isset($data['data']['package_guid'])) {
    // store package_id and package_guid with your internal record
}

Get signature request status

PHP
$ch = curl_init("https://toolkit.undersign.app/api/v1.1/signature-requests/<package-guid>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer " . getenv('UNDERSIGN_API_TOKEN')
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);