A PHP SDK for the Wati.io WhatsApp API. Provides pre-built API classes for common operations.
This package requires PHP 8.3 or higher.
composer require "phpjuice/wati-sdk"- Log in to your Wati Account
- Navigate to API Docs in the top menu
- Copy your API Endpoint URL and Bearer Token
<?php
use Wati\Http\WatiClient;
use Wati\Http\WatiEnvironment;
use Wati\Api\GetContacts;
// Get this URL from your Wati Dashboard (API Docs section)
// It includes your tenant ID: https://your-instance.wati.io/{tenantId}
$endpoint = "https://your-instance.wati.io/123456";
$bearerToken = "your-bearer-token";
// Create environment and client
$environment = new WatiEnvironment($endpoint, $bearerToken);
$client = new WatiClient($environment);
// Use pre-built API classes
$response = $client->send(new GetContacts());
$contacts = json_decode($response->getBody()->getContents(), true);The SDK includes a Laravel service provider for easy integration.
Add the following to your config/services.php:
'wati' => [
'endpoint' => env('WATI_ENDPOINT'),
'token' => env('WATI_TOKEN'),
],Add to your .env file:
WATI_ENDPOINT=https://your-instance.wati.io/123456
WATI_TOKEN=your-bearer-tokenThe service provider is auto-discovered. Simply inject or resolve WatiClient:
use Wati\Http\WatiClient;
use Wati\Api\GetContacts;
class ContactController
{
public function __construct(
private readonly WatiClient $wati
) {}
public function index()
{
$response = $this->wati->send(new GetContacts());
return json_decode($response->getBody()->getContents(), true);
}
}| Class | Method | Endpoint |
|---|---|---|
GetContacts |
GET | /api/v1/getContacts |
| Class | Method | Endpoint |
|---|---|---|
GetMessageTemplates |
GET | /api/v1/getMessageTemplates |
SendTemplateMessage |
POST | /api/v1/sendTemplateMessage |
<?php
use Wati\Api\GetContacts;
// Get the first page with 50 contacts (default)
$response = $client->send(new GetContacts());
// Get a specific page with a custom page size
$response = $client->send(new GetContacts(pageNumber: 2, pageSize: 100));<?php
use Wati\Http\Exceptions\AuthenticationException;
use Wati\Http\Exceptions\RateLimitException;
use Wati\Http\Exceptions\ValidationException;
use Wati\Http\Exceptions\WatiApiException;
use Wati\Http\Exceptions\WatiException;
try {
$response = $client->send(new GetContacts());
} catch (AuthenticationException $e) {
// Invalid bearer token - check credentials
} catch (RateLimitException $e) {
// Rate limited - wait and retry
$retryAfter = $e->getRetryAfter();
} catch (ValidationException $e) {
// Invalid request parameters
$errors = $e->getResponseData();
} catch (WatiApiException $e) {
// Other API errors (4xx, 5xx)
$statusCode = $e->getStatusCode();
} catch (WatiException $e) {
// Connection or other HTTP errors
}For full API documentation, visit Wati API Docs.
Please see the CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email the author instead of using the issue tracker.
Please see the License file.