Whatsapp API send message PHP

How to Send a Message by WhatsApp API using PHP

Before you begin, ensure that you have installed PHP and the curl extension on your server or local machine.

Authentication

Sign up and connect any phone number to the channel that appears on the dashboard.

Don't worry, you can disconnect at any time, but it's necessary for WhatsApp automation. To do this, navigate to your personal account where you'll find a QR code for the available channel. Then, open WhatsApp on your mobile device, go to Settings -> Linked devices -> Link a device -> Scan QR code.

Now save the generated API-Key token:

How to Send WhatsApp API Message using PHP

Send your first WhatsApp message ๐Ÿ˜Š

To send a text message, you need to make a request to:

POST https://gate.whapi.cloud/messages/text

<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://gate.whapi.cloud/messages/text', [
  'body' => '{"typing_time":0,"to":"14409416972","body":"Hello"}',
  'headers' => [
    'accept' => 'application/json',
    'authorization' => 'Bearer i4sbo2dXBNB1SbBvVwccPwpCzBDhVmcs',
    'content-type' => 'application/json',
  ],
]);

echo $response->getBody();
  • 'to': The recipientโ€™s WhatsApp number with international format e.g., 14409416972 or chatID for contact or group e.g 14409416972@s.whatsapp.net or 120361234567890@g.us

  • 'body' : Message text.

Save the PHP script and run it on your server. The specified message will be sent to the specified WhatsApp number. Remember to replace variables with your actual details.

Please note that this is a basic example and doesn't include any error handling. For a production environment, ensure to add appropriate error and exception handling. Please don't hesitate to reach out to share your experiences or pose any questions you might have.

Quickstart

Use the source code of ready-made WhatsApp bots as a platform for an easy start. Download, insert your token and launch!

Get Started Free


Send Media Message

Additional endpoint for easy send media-file as message. Use request body as file and inpath parameters for send parameters. Media message can be one of the following types:

Send Image

Send Document

Send Audio

Send Voice

You can Send a ppt audio recording to the phone number or group, But WhatsApp is sensitive to this extension, you need to be in OGG format and the codecs should be the opus, For more information, you can check out this article.

Send Video

Send GIF

Send Contact

Send Contact List

Send Location

Send Sticker

Last updated