Hi,
I’m trying with PHP but always getting this error my code like this
<?php
require_once 'vendor/autoload.php';
use DocuSign\eSign\Client\ApiClient;
use DocuSign\eSign\Configuration;
use DocuSign\eSign\Api\EnvelopesApi;
use DocuSign\eSign\Model\EnvelopeDefinition;
use DocuSign\eSign\Model\Signer;
use DocuSign\eSign\Model\Recipients;
use DocuSign\eSign\Model\Document;
use Firebase\JWT\JWT;
$integrationKey = '9eaed807-bd9f-4d38-b858-37f6eccc6b73'; // Your Integration Key
$userId = 'd4300ed6-aa42-47cd-b687-01c825726abd'; // Your User ID (GUID)
$privateKey = file_get_contents('key.pem'); // Path to your private key
$accountId = '8c637b59-afa2-4821-8c5d-981bacf4ddde'; // Your Account ID
// Set the current time and expiration time
$now = time();
$expiration = $now + 3600000; // Token valid for 1 hour
// Create the JWT payload
$payload = o
'iss' => $integrationKey,
'sub' => $userId,
'iat' => $now,
'exp' => $expiration,
'aud' => 'demo.docusign.net', //aud: Should be set to account.docusign.com for production or demo.docusign.net for the demo environment.
'scope' => 'signature impersonation'
];
// Generate the JWT
$jwt = JWT::encode($payload, $privateKey, 'RS256');
// Create a new ApiClient and configure it
$config = new Configuration();
$config->setHost('https://demo.docusign.net/restapi'); // Use demo for sandbox
$apiClient = new ApiClient($config);
// Add the Authorization header
$apiClient->getConfig()->addDefaultHeader('Authorization', 'Bearer ' . $jwt);
// Create an envelope definition
$envelopeDefinition = new EnvelopeDefinition();
$envelopeDefinition->setEmailSubject("Please sign this document");
// Create a document
$document = new Document();
$document->setDocumentBase64(base64_encode(file_get_contents('test.pdf')));
$document->setName('Sample Document');
$document->setFileExtension('pdf');
$document->setDocumentId('1');
$envelopeDefinition->setDocuments(i$document]);
// Create a signer
$signer = new Signer();
$signer->setEmail('test@gmail.com');
$signer->setName('Uday');
$signer->setRecipientId('1');
// Add signer to recipients
$recipients = new Recipients();
$recipients->setSigners($$signer]);
// Add recipients to envelope
$envelopeDefinition->setRecipients($recipients);
// Set envelope status to 'sent'
$envelopeDefinition->setStatus('sent');
// Create EnvelopesApi instance
$envelopesApi = new EnvelopesApi($apiClient);
try {
// Send the envelope
$result = $envelopesApi->createEnvelope($accountId, $envelopeDefinition);
echo "Envelope has been sent successfully! Envelope ID: " . $result->getEnvelopeId();
} catch (Exception $e) {
echo "Error sending envelope: " . $e->getMessage();
}