How to send a WhatsApp message with JavaScript and Node.js

WhatsApp is a messaging service used by people all over the world. With Chat API you can programmatically receive and send WhatsApp messages using simple HTTP requests.
Integrate WhatsApp with any marketing or business platform i.e. Woocommerce, Shopify, Autoresponder, CRM, ERP, etc.

Let's walk through how to use JavaScript to send a message over WhatsApp.

Before you begin, make sure that Node.js and npm installed (do this first if you haven't already) 

You will need an account in our service. Create your account in Chat-Api. It's free! 
After that, you will be redirected to the admin panel, where your personal instance will be generated and created for you.

Go to your personal account and get a QR code there. Next, open WhatsApp on your mobile phone, go to Settings -> WhatsApp Web -> Scan a QR code.

Sending a WhatsApp message with Node.js

var request = require('request'); //bash: npm install request
// URL for request POST /message
var url = 'https://foo.chat-api.com/message?token=83763g87x';
var data = {
    phone: '15034365851', // Receivers phone
    body: 'Hello, world!', // Message
};
// Send a request
request({
    url: url,
    method: "POST",
    json: data
});

Just copy and use it! 
Don't use brackets, hyphens and any other formatting symbols in the phone. Use only digits.

You will only need to substitute your token from your personal account into the $token variable and instance number (or ApiURL)
Get API key, try it today!

What if I want to do this with another language?
You just successfully sent your first WhatsApp message using JavaScript, but what if you want to do this in PHP? We have other blog posts you can check out for that: How to send whatsapp message with PHP or How to send a WhatsApp message with Python

Feel free to reach out and share your experiences or ask any questions.

Get free demo

Recommendation

See how chatbot works on our API right now

Send a message to +1 (518) 704-3963 through WhatsApp and test the our API.

Our WhatsApp API gateway service for sending and receiving messages, notification, scheduler, reminder, group message, tracking, and chatbots with simple integration for your business

Questions and wishes: nik@chat-api.com
To top