PHP
This PHP snippet describes the sequence of API calls needed to create and activate a Signature Request.
<?php
$baseUrl = 'https://api-sandbox.yousign.app/v3';
$apiKey = 'REPLACE_WITH_YOUR_API_KEY';
$pdfDocumentPath = './test.pdf';
$curl = curl_init();
## 1 - Create a Signature Request:
$data = <<<JSON
{
"name": "The name of your Signature Request",
"delivery_mode": "email",
"timezone": "Europe/Paris"
}
JSON;
curl_setopt_array($curl, [
CURLOPT_URL => sprintf('%s/signature_requests', $baseUrl),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => [
sprintf('Authorization: Bearer %s', $apiKey),
'Content-Type: application/json'
],
]);
$initiateSignatureRequestResponse = curl_exec($curl);
$signatureRequest = json_decode($initiateSignatureRequestResponse, true);
$signatureRequestId = $signatureRequest['id'];
## 2 - Add a Document to the Signature Request:
curl_setopt_array(
$curl,
[
CURLOPT_URL => sprintf('%s/signature_requests/%s/documents', $baseUrl, $signatureRequestId),
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => [
'file' => new CURLFile($pdfDocumentPath, 'application/pdf'),
'nature' => 'signable_document',
'parse_anchors' => 'true'
],
CURLOPT_HTTPHEADER => [
sprintf('Authorization: Bearer %s', $apiKey),
],
]);
$documentUploadResponse = curl_exec($curl);
$document = json_decode($documentUploadResponse, true);
$documentId = $document['id'];
## 3 - Add a Signer to the Signature Request:
$data = <<<JSON
{
"info": {
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"phone_number": "+33700000000",
"locale": "fr"
},
"signature_authentication_mode": "no_otp",
"signature_level": "electronic_signature",
"fields": [
{
"document_id": "{$documentId}",
"type": "signature",
"height": 37,
"width": 85,
"page": 1,
"x": 0,
"y": 0
}
]
}
JSON;
curl_setopt_array($curl, [
CURLOPT_URL => sprintf('%s/signature_requests/%s/signers', $baseUrl, $signatureRequestId),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => [
sprintf('Authorization: Bearer %s', $apiKey),
'Content-Type: application/json'
],
]);
$addSignerResponse = curl_exec($curl);
## 4 - Activate the Signature Request:
curl_setopt_array($curl, [
CURLOPT_URL => sprintf('%s/signature_requests/%s/activate', $baseUrl, $signatureRequestId),
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
sprintf('Authorization: Bearer %s', $apiKey),
'Content-Type: application/json'
],
]);
$activateSignatureRequestResponse = curl_exec($curl);
curl_close($curl);
echo $activateSignatureRequestResponse;
Updated 7 months ago