How to send a WhatsApp message in Python

WhatsApp is practically the most popular messaging service widely used all over the world. The chat bots development market for WhatsApp is growing rapidly. In this guide, we will show how to send WhatsApp messages via ChatAPI using Python. This guide for programmers will help to take the first step in creating a bot.

So, how to send a WhatsApp message to Python using the Chat API service

To start

If you do not already have Python installed on your computer, go to the Python downloads page and install the latest version.

Create your account at Chat-Api. It's free! 
After that you will be redirected to the admin panel where your personal instance will be created. You need to connect your phone number with our API.

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

Here is the script that will send the message:

import requests

url = 'https://api.chat-api.com/instance123/message?token=83763g87x'
data = ({"phone": "15039740922"}, {"body": "Hello, World!"})
res = requests.post(url, json=data)
print res.text

Just copy and use it! By the way, do not use brackets, hyphens or any other formatting symbols in the telephone number. Use only numbers, as in our example.

Don't forget, you will need to substitute your token from your account and instance number (or replace the whole ApiURL)

What if I want to do this in another programming language?
You have just successfully sent your first WhatsApp message, this is the first step to developing bots or integrations, and did it using Python, but what if you want to do this in PHP or JavaScript? We have other blog posts, you can study other material: How to send Whatsapp message with PHP or Sending WhatsApp message with Node.js

Request API key, try it yourself, it's easy!

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