PHP / Laravel SDK
Coming Soon
The sendapi/php Composer package is currently under development and has not yet been published to Packagist. The examples below show the planned SDK interface. In the meantime, use any HTTP client (e.g., Laravel's Http facade) with the REST API endpoints directly.
The official SendAPI PHP SDK will integrate natively with Laravel via a service provider and facade.
Installation
bash
composer require sendapi/phpLaravel Setup
After installing, publish the config:
bash
php artisan vendor:publish --provider="SendAPI\Laravel\ServiceProvider"Add your API key to .env:
env
SENDAPI_KEY=sk_live_YOUR_API_KEY
SENDAPI_WEBHOOK_SECRET=your_webhook_secretUsage with Facade
php
use SendAPI\Facades\SendAPI;
// Send a WhatsApp message
$message = SendAPI::whatsapp()->send([
'session_id' => 'sess_01H8BKF...Z2T',
'to' => '+447700900000',
'type' => 'text',
'text' => ['body' => 'Hello from SendAPI!'],
]);
// Send an SMS
$sms = SendAPI::sms()->send([
'to' => '+447700900000',
'content' => 'Your verification code is 847291',
]);
// Send an Email
$email = SendAPI::email()->send([
'to' => 'alice@example.com',
'subject' => 'Welcome!',
'html' => '<h1>Welcome to MyApp!</h1>',
]);OTP Verification
php
// Send OTP
$verification = SendAPI::verify()->send([
'to' => '+447700900000',
'channel' => 'auto',
'brand_name' => 'MyApp',
]);
// Verify the user-submitted code
$result = SendAPI::verify()->check([
'id' => $verification->id,
'code' => $request->input('otp'),
]);
if ($result->valid) {
// Authenticate the user
Auth::login($user);
}Webhook Handling
php
use SendAPI\Laravel\Http\Controllers\WebhookController;
// In routes/api.php
Route::post('/webhooks/sendapi', [WebhookController::class, 'handle']);Create a listener in app/Listeners:
php
use SendAPI\Laravel\Events\MessageReceived;
class HandleWhatsAppMessage
{
public function handle(MessageReceived $event): void
{
$message = $event->message;
logger("Message from: {$message['from']}");
}
}Error Handling
php
use SendAPI\Exceptions\SendAPIException;
use SendAPI\Exceptions\RateLimitException;
try {
SendAPI::whatsapp()->send([...]);
} catch (RateLimitException $e) {
// Retry after $e->retryAfter seconds
} catch (SendAPIException $e) {
logger()->error("SendAPI error: " . $e->getMessage());
}