phpjuice/wati-http-client

PHP Http Client for Wati.io WhatsApp API

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 1

pkg:composer/phpjuice/wati-http-client

v1.0.0 2026-02-20 19:07 UTC

This package is auto-updated.

Last update: 2026-02-21 00:22:31 UTC


README

CI PHP Version Latest Stable Version Total Downloads License

A PHP HTTP Client for the Wati.io WhatsApp API. Provides a simple, fluent API to interact with Wati's REST API.

Installation

This package requires PHP 8.3 or higher.

composer require "phpjuice/wati-http-client"

Setup

Get Your Credentials

  1. Log in to your Wati Account
  2. Navigate to API Docs in the top menu
  3. Copy your API Endpoint URL and Bearer Token

Create a Client

<?php

use Wati\Http\WatiClient;
use Wati\Http\WatiEnvironment;

// Your API endpoint and bearer token from the Wati dashboard
$endpoint = "https://your-instance.wati.io";
$bearerToken = "your-bearer-token";

// Create environment
$environment = new WatiEnvironment($endpoint, $bearerToken);

// Create client
$client = new WatiClient($environment);

Usage

Making Requests

Extend WatiRequest to create your API requests:

<?php

use Wati\Http\WatiRequest;
use GuzzleHttp\Psr7\Utils;

class GetContactsRequest extends WatiRequest
{
    public function __construct(int $page = 1, int $pageSize = 50)
    {
        parent::__construct(
            'GET',
            "/api/v1/getContacts?page={$page}&pageSize={$pageSize}",
            ['Accept' => '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

use GuzzleHttp\Utils;

// Get contacts
$response = $client->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.

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

Changelog

Please see the CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING 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 file.