WhatsApp API Documentation

The WhatsApp APIĀ  enables you to send and receive messages through your Whatsapp account.

Warning:
The WhatsApp API is based on the WhatsApp WEB protocol which means that your account can be banned by the WhatsApp anti-spam system when some recipients click the “BLOCK” or “SPAM”. So, avoid sending messages to people who did not subscribe to your list or platform.

API Documentation

To send and receive messages, please ensure that the phone which you have your WhatsApp account is connected to the internet.

Send Message

Test URL: https://wasapng.com/client/test-send
Live URL: https://wasapng.com/client/live-send

You are to use the test API key on the test URL and the premium API key on the live URL.
You can get your API key for your WhatsApp channel in your client area here.

Post Parameters:

  • username – Your username
  • apikey – API key
  • phone – recipient’s phone number
  • type –
    1 is for text
    2 is for file
  • message – your message

On the test URL, you can only send message to the number you registered on the WhatsApp channel you created. With the live API, you can send up to 10,000 messages per day.

Ensure your WhatsApp is connected to the internet when using our WhatsApp API.


Sample PHP Code to Send Message


 $postdata = http_build_query( 
array( 
'username' => 'user', 
'apikey' => 'apikey', 
'phone' => '08128496819', 
'type' => '1', 
'message' => 'Hello there!'
 ) );

$opts = array('http' => 
array( 
'method' => 'POST', 
'header' => 'Content-Type: application/x-www-form-urlencoded', 
'content' => $postdata ) );

$context = stream_context_create($opts); 

@$result = file_get_contents ('https://wasapng.com/client/live-send', false, $context);

echo $result;

Response

{
    "sent": true,
    "message": "ok"
}

Sample PHP Code to Send File

When sending a file, the message parameter will be the link/URL to the file.

You will also need to add 2 more parameters;

  • filename – the name of the file with the extension.
  • caption – the message that will be displayed with the file.

$postdata = http_build_query(
array(
'username' => 'username',
'apikey' => 'PRM-xxxx',
'phone' => '08128496819',
'type' => '2',
'message' => 'https://wasapng.com/whatsapp-bots-ng.jpg',
'filename' => 'whatsappbots.jpg',
'caption' => 'This is our official logo',
)
);

$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);

$context = stream_context_create($opts);

@$result = file_get_contents('https://wasapng.com/client/live-send', false, $context);

echo $result;


Receive Message

New messages received on your WhatsApp account will be forwarded to your webhook URL. You can set your webhook URL for your WhatsApp channel. Your URL could be http or https.
Please note that the webhook only applies to a live or premium account.

Two parameters will be pushed to your Webhook;

  • phone – the sender’s phone number
  • message – the message received

Sample PHP code to receive messages on your webhook


if (isset($_POST['phone']) && isset($_POST['message'])){
$sender=$_POST['phone'];
$message=$_POST['message'];

//you can do whatever you want with the information received
}

See how to build a simple Whatsapp Bots here

We offer Whatsapp chat bot creation for business owners. Click here