saade/z-api-php-sdk
A PHP SDK for integrating Z-API's WhatsApp service into Laravel or any PHP application. It provides a clean client for managing instances, sending text and media messages, handling webhooks, and automating WhatsApp workflows with Composer-ready convenience.
Install the package via Composer:
composer require saade/z-api-php-sdk
Publish the configuration file (if the package provides one):
php artisan vendor:publish --tag="z-api-config"
Add your Z-API credentials to .env. Typical values include the instance ID, token, and client token (used for webhook security):
ZAPI_INSTANCE_ID=your-instance-id
ZAPI_TOKEN=your-instance-token
ZAPI_CLIENT_TOKEN=your-client-token
The quickest first use case is sending a WhatsApp text message. Resolve the SDK from the container (or use its facade, if provided) and call the relevant resource method—for example:
use Saade\ZApi\ZApi;
$response = ZApi::messages()->sendText(
phone: '5511999999999',
message: 'Hello from Laravel!'
);
Start by reading the package README for the exact resource names and method signatures. Most day‑to‑day work will involve the messages, instances, and contacts resources.
Wrap SDK calls in your own service or action classes. Keep controllers thin by delegating message sending, contact syncing, and instance management to dedicated classes. This makes testing and swapping the SDK easier.
class SendWhatsAppMessage
{
public function __construct(private ZApi $zapi) {}
public function handle(string $phone, string $text): void
{
$this->zapi->messages()->sendText($phone, $text);
}
}
Queue outgoing messages. Sending a message is an external HTTP call; always dispatch it through a queued job to avoid blocking web requests and to benefit from retries.
SendWhatsAppMessage::dispatch($phone, $text)->onQueue('whatsapp');
Handle webhooks in a dedicated controller. Z-API sends delivery statuses and incoming messages via webhooks. Validate the request using the client token (the package may provide a middleware or helper), then dispatch a job to process the payload asynchronously.
Use Saloon’s testing helpers. Since the SDK is built on Saloon, you can fake HTTP responses in your tests:
ZApi::fake([
SendTextRequest::class => ZApi::response(['messageId' => 'abc123']),
]);
Support multiple instances. If your application manages more than one WhatsApp instance, instantiate the SDK with per‑instance credentials rather than relying solely on the global config. Check whether the package exposes a factory or a ZApi::forInstance() method.
.env, run php artisan config:clear (or config:cache in production). Stale config is a common source of “invalid token” errors.Saloon\Exceptions\Request\RequestException and log the response body for debugging.ZApi::client() method or a config option to register middleware.^1.1 in composer.json and avoid downgrading to v1.0.0.How can I help you explore Laravel packages today?