green-api/whatsapp-api-client-php REST API Client

v0.2 2023-01-18 10:46 UTC

This package is auto-updated.

Last update: 2024-07-14 05:39:18 UTC


Total Downloads Downloads per month License

PHP library for integration with WhatsApp messenger via API of service. To use the library you have to get a registration token and an account id in the personal area. There is a free developer account tariff plan.


You can find REST API documentation by url. The library is a wrapper for REST API, so the documentation at the above url applies to the library as well.


Via Composer:

composer require green-api/whatsapp-api-client-php


require './vendor/autoload.php';


To send a message or to execute some other Green-API method, you have to have the WhatsApp account in the phone application to be authorized. To authorize your account please go to the personal area and scan a QR-code using the WhatsApp application.

Running index.php

php -S localhost:8080


How to initialize an object

$greenApi = new GreenApiClient( ID_INSTANCE, API_TOKEN_INSTANCE );

Sending a text message to a WhatsApp number

$result = $greenApi->sending->sendMessage('', 'Message text');

Example url: sendTextMessage.php

Please note that keys can be obtained from environment variables:

require './vendor/autoload.php';

define( "ID_INSTANCE", getenv("ID_INSTANCE" ));

Sending an image via URL

$result = $greenApi->sending->sendFileByUrl(
        '', '',
        'googlelogo_color_272x92dp.png', 'Google logo');

Example url: sendPictureByLink.php

Sending an image by uploading from the disk

$result = $greenApi->sending->sendFileByUpload('',
        'C:\Games\PicFromDisk.png', 'PicFromDisk.jpg', 'Picture from disk');

Example url: sendPictureByUpload.php

Group creation and sending a message to the group

$chatIds = [
$resultCreate = $greenApi->groups->createGroup('GroupName', $chatIds );

if ($resultCreate->code == 200)
	$resultSend = $greenApi->sending->sendMessage($resultCreate->data->chatId, 
	    'Message text');

IMPORTANT: If one tries to create a group with a non-existent number, WhatsApp may block the sender's number. The number in the example is non-existent.

Example url: createGroupAndSendMessage.php

Receive incoming messages by HTTP API

The general concept of receiving data in the Green API is described here To start receiving messages by the HTTP API you need to execute the library method:


onEvent - your method which should contain parameters:

Message body types and formats here

This method will be called when an incoming message is received. Next, process messages according to the business logic of your system.

Examples list

The full list of the library methods

Service methods documentation


Licensed under MIT terms. Please see file LICENSE