https://github.com/phpjuice/wati-http-client
PHP Http Client for Wati.io Rest API
https://github.com/phpjuice/wati-http-client
wati whatsapp whatsapp-api
Last synced: 6 days ago
JSON representation
PHP Http Client for Wati.io Rest API
- Host: GitHub
- URL: https://github.com/phpjuice/wati-http-client
- Owner: phpjuice
- License: mit
- Created: 2026-02-20T19:00:32.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-02-28T19:30:11.000Z (24 days ago)
- Last Synced: 2026-02-28T22:49:41.541Z (23 days ago)
- Topics: wati, whatsapp, whatsapp-api
- Language: PHP
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Wati HTTP Client
[](https://github.com/phpjuice/wati-http-client/actions/workflows/php.yml)
[](https://php.net)
[](https://packagist.org/packages/phpjuice/wati-http-client)
[](https://packagist.org/packages/phpjuice/wati-http-client)
[](https://opensource.org/licenses/MIT)
[](./.github/CONTRIBUTING.md)
A PHP HTTP Client for the [Wati.io](https://wati.io) WhatsApp API. Provides a simple, fluent API to interact with Wati's
REST API.
## Related Packages
For a higher-level, feature-rich integration, consider using [wati-sdk](https://github.com/phpjuice/wati-sdk). It provides ready-to-use request classes, response DTOs, and additional convenience features built on top of this HTTP client.
## Installation
This package requires PHP 8.3 or higher.
```bash
composer require "phpjuice/wati-http-client"
```
## Setup
### Get Your Credentials
1. Log in to your [Wati Account](https://app.wati.io)
2. Navigate to **API Docs** in the top menu
3. Copy your **API Endpoint URL** and **Bearer Token**
### Create a Client
```php
60, // Request timeout in seconds (default: 30)
'connect_timeout' => 15, // Connection timeout in seconds (default: 10)
'verify' => true, // Verify SSL certificate (default: true)
'proxy' => 'tcp://localhost:8080', // Proxy URL (default: null)
'debug' => false, // Enable debug mode (default: false)
]);
```
## Usage
### Making Requests
Extend `WatiRequest` to create your API requests:
```php
'application/json']
);
}
}
class SendTemplateMessageRequest extends WatiRequest
{
public function __construct(string $phoneNumber, string $templateName, array $parameters = [])
{
$body = json_encode([
'template_name' => $templateName,
'broadcast_name' => $templateName,
'parameters' => $parameters,
]);
parent::__construct(
'POST',
"/api/v1/sendTemplateMessage?whatsappNumber={$phoneNumber}",
[
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
Utils::streamFor($body)
);
}
}
```
### Execute Requests
```php
send(new GetContactsRequest());
$data = Utils::jsonDecode($response->getBody()->getContents(), true);
// Send a template message
$response = $client->send(new SendTemplateMessageRequest(
'1234567890',
'hello_world',
['name' => 'John']
));
```
## API Reference
For full API documentation, visit [Wati API Docs](https://docs.wati.io/reference/introduction).
### Available Endpoints
- **Messaging**: Send templates, session messages, interactive messages
- **Contacts**: Get, add, update contacts
- **Conversations**: Messages, status updates
- **Templates**: Get and send message templates
- **Campaigns**: Manage broadcasts
## Error Handling
The client throws specific exceptions for different error scenarios:
```php
send(new GetContactsRequest());
} catch (AuthenticationException $e) {
// Invalid bearer token - check credentials
echo "Auth failed: " . $e->getMessage();
} catch (RateLimitException $e) {
// Rate limited - wait and retry
$retryAfter = $e->getRetryAfter(); // seconds to wait
} catch (ValidationException $e) {
// Invalid request parameters
$errors = $e->getResponseData();
} catch (WatiApiException $e) {
// Other API errors (4xx, 5xx)
$statusCode = $e->getStatusCode();
$data = $e->getResponseData();
} catch (WatiException $e) {
// Connection or other HTTP errors
echo "Request failed: " . $e->getMessage();
}
```
## Changelog
Please see the [CHANGELOG](changelog.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](./.github/CONTRIBUTING.md) for details.
## Security
If you discover any security-related issues, please email the author instead of using the issue tracker.
## License
Please see the [License](./LICENSE) file.