hellosign/hellosign-php-sdk
Deprecated official HelloSign API PHP SDK (PHP 8+; PHP 7 via 3.7.*). Provides HelloSign\Client for API key, email/password, or OAuth auth; supports core API actions like account and signature requests. Use dropbox/sign SDK for new work.
## Getting Started
### Minimal Setup
1. **Installation**
```bash
composer require hellosign/hellosign-php-sdk:^3.8.0
Verify the package loads in composer.json under require with the updated version constraint.
First Use Case: Sending a Signature Request (PHP 8.1 Compatible)
use HelloSign\Client;
use HelloSign\Configuration;
$config = Configuration::getDefaultConfiguration()
->setApiKey('YOUR_API_KEY'); // From HelloSign Dashboard
$client = new Client($config);
$request = new \HelloSign\Model\SignRequest();
$request->setTitle('Laravel Contract')
->setRequesterEmail('user@example.com')
->addSigner((new \HelloSign\Model\Signer())
->setEmail('signer@example.com')
->setName('John Doe')
)
->addDocument((new \HelloSign\Model\Document())
->setFileUrl('https://example.com/contract.pdf')
->setName('Contract.pdf')
);
$response = $client->getSignRequestsApi()->createSignRequest($request);
Where to Look First
src/Api for available endpoints.examples folder (if available).Signature Request Lifecycle (Updated for PHP 8.1)
createSignRequest() with a SignRequest object (now compatible with PHP 8.1).getSignRequest() with the signRequestId to check completion.
$request = $client->getSignRequestsApi()->getSignRequest('SIGN_REQUEST_ID');
if ($request->getStatus() === 'completed') {
$file = $client->getSignRequestsApi()->getDocument('SIGN_REQUEST_ID', 'DOCUMENT_ID');
}
Document Handling (PHP 8.1 Compatible)
fileUrl (public URL) or base64-encoded content:
$document = (new \HelloSign\Model\Document())
->setFileUrl('https://example.com/file.pdf');
// OR
$document->setFileBase64('base64_encoded_string');
Template Reuse (PHP 8.1 Compatible)
SignRequest as a template:
$template = $client->getTemplatesApi()->createTemplate($request);
// Later, reuse with:
$client->getTemplatesApi()->signTemplate('TEMPLATE_ID', ['signer_emails' => [...]]);
Laravel Service Provider (PHP 8.1) Bind the client to the container for dependency injection:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton(Client::class, function ($app) {
$config = Configuration::getDefaultConfiguration()
->setApiKey(config('services.hellosign.key'));
return new Client($config);
});
}
Configure API key in .env:
HELLOSIGN_KEY=your_api_key_here
Queue Delayed Actions (PHP 8.1) Use Laravel Queues to defer status checks or webhook processing:
// Dispatch a job to check status later
CheckSignRequestStatus::dispatch($signRequestId)->delay(now()->addMinutes(5));
Error Handling (PHP 8.1) Wrap API calls in try-catch:
try {
$response = $client->getSignRequestsApi()->createSignRequest($request);
} catch (\HelloSign\ApiException $e) {
Log::error('HelloSign API Error: ' . $e->getMessage());
return back()->with('error', 'Failed to send signature request.');
}
Deprecated Endpoints (Critical)
getSignRequest() may not support all status fields in newer API versions.PHP Version Compatibility
Rate Limiting
$request = Cache::remember("hellosign_request_{$id}", now()->addMinutes(5), fn() =>
$client->getSignRequestsApi()->getSignRequest($id)
);
File Size Limits
if ($file->getSize() > 50 * 1024 * 1024) {
throw new \Exception('File too large. Max 50MB allowed.');
}
Webhook Delays
Enable SDK Debugging (PHP 8.1)
$config->setDebug(true); // Logs HTTP requests/responses
Check logs for HelloSign entries.
Validate API Key Test with a dummy request first:
$client->getAccountsApi()->getAccount(); // Should return account details
PHP 8.1 Strict Typing Ensure all model properties are type-hinted correctly. Example:
$signer = new \HelloSign\Model\Signer();
$signer->setEmail('user@example.com'); // Ensure no type mismatches
Custom Signer Fields (PHP 8.1)
Extend the Signer model to add custom fields:
$signer = new \HelloSign\Model\Signer();
$signer->setEmail('user@example.com')
->setName('Custom Name')
->setCustomFields(['department' => 'Engineering']); // Use metadata
PDF Annotations (PHP 8.1)
Use SignHere tags in documents:
$document->setSignHereTags([
(new \HelloSign\Model\SignHere())
->setAnchorX(100)
->setAnchorY(200)
->setAnchorUnit('px')
->setAnchorType('corner')
->setPageNumber(1)
]);
Laravel Notifications (PHP 8.1) Integrate with Laravel Notifications for signer reminders:
use Illuminate\Notifications\Notification;
class SignatureReminder extends Notification
{
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Please Sign Your Document')
->line('Your document is awaiting your signature.');
}
}
$config->setHost('https://api.sandbox.hellosign.com'); // Sandbox
$config->setConnectTimeout(30); // 30 seconds
$config->setReadTimeout(60); // 60 seconds
AppServiceProvider to track migration status:
// TODO: Migrate to hellosign/hellosign-php-sdk (OpenAPI branch) after deprecation
How can I help you explore Laravel packages today?