WhatsApp API, tips for developers

How to send WhatsApp text messages

Published by Vanessa - June 20, 2019

How to send WhatsApp text messages with Mercury API

How to best use WhatsApp API?

If you are looking for an easy solution to send WhatsApp messages with the APIs, then you are in the right place.

Let's try to understand what we are talking about...
Anyone who knows WhatsApp also knows how powerful it can be for marketing strategies, or to the customers management and retention. We at Mercury know this well, which is why we want to offer a tool for automatically sending WhatsApp messages.

Let's see how to do it with Mercury. 🤔

First you need to get the API token. To get it you need to log in to Mercury and reach the Developer section. Then enable the REST API service to get the token.
Let's see this step in the screenshot below:

mercury-app-whatsapp-api-enable

mercury-app-whatsapp-api-token

Url API.

Please note that you can visit the API URL at this web address: https://api.mercury.chat/sdk.

To complete the authentication you have to pass the api_token parameter in the query string parameter. You can retrieve the token API within the dashboard.

mercury-app-whatsapp-api-authentication

How to send a WhatsApp text message.

When you send a message, the message will be added to the queue for sending and delivery even if the phone is disconnected from Internet or the authorization doesn't pass. Only one of the two parameters is needed to determine the destination: chatId or phone.
Let's look at an example of the API calls in NodeJs.

var request = require("request");

var options = { method: 'POST',
url: 'https://api.mercury.chat/sdk/v1/whatsapp/sendMessage',
qs: { api_token: 'tokenAPI', instance: 'instance_number' },
headers: { 'Content-Type': 'application/json' },
body: { phone: 17472822486, body: 'HI' },
json: true };

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});

Remember that the Mercury APIs are available in your favorite programming language. For example, Java, C #, Ruby, Go, Python and many others. Find out all the features of Mercury's WhatsApp API.