Automate your WhatsApp messages using Wassenger and Python to streamline operations and ensure prompt message delivery. This integration allows you to send personalized messages, track delivery and responses, and reduce manual workload, enhancing overall customer engagement and productivity. Dive into our guide to learn how to implement this powerful solution and elevate your communication strategy with Wassenger and Python.
🫣 Don’t want to use programming? No problem! Explore our new no-code WhatsApp Campaigns feature. Import your contacts, define a message, set a delivery date and relax! 🥳 🥳
🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and getting started in minutes!
Requirements
- To have a WhatsApp number already linked to the platform and online.
- Message recipient phone number with international prefix in E164 format. Example:
+12345678900
. Validate the phone number format here.
API endpoint
We will use the following API endpoint to send messages to a group:
Prepare the request
Target API URL using the POST method
https://api.wassenger.com/v1/messages
Required HTTPS headers > Obtain your API key here
Content-Type: application/json
Token: $API_TOKEN
Use body in JSON format
{
"phone": "+1234567890",
"message": "Hello world, this is a sample message"
}
🖥️ Looking for a code example? Go to the API live tester and get ready-to-use code examples in 15+ programming languages, including Python, JavaScript, PHP, C#, Java, Ruby, Go, Powershell, cURL and more.
🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!
Send automated messages with Python
- Install
requests
: Make sure you have therequests
library installed (pip install requests
). - Set up the request: Create the payload and headers.
- Send the request: Use the
requests
library to send the request and handle the response.
import requests
url = "https://api.wassenger.com/v1/messages"
payload = {
"phone": "+1234567890",
"message": "Hello world, this is a sample message"
}
headers = {
"Content-Type": "application/json",
"Token": "YOUR_ACTUAL_API_KEY"
}
try:
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status() # Raise an exception for HTTP errors
print("Message sent successfully.")
print("Response:", response.json()) # Assuming the response is in JSON format
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except Exception as err:
print(f"An error occurred: {err}")
- Setup: The
url
,payload
, andheaders
variables are defined with the necessary values. - Sending the Request: The
requests.post
method sends the POST request to the specified URL with the JSON payload and headers. - Error Handling: The
response.raise_for_status
method raises an exception for HTTP errors, which are caught and displayed. This ensures that any issues with the request (such as incorrect API keys or malformed payloads) are reported.
Live API testing
You can live-test and play with the API directly from your browser.
Once you are done testing, get the auto-generated code example in your preferred programming language and you will be ready to go.
FAQ
How to send messages to multiple phone numbers
You just have to send multiple API requests, one per target phone number.
For instance, if you want to send a message to 10 phone numbers, you should send 10 independent HTTPS requests to the API.
There is no option to send multiple messages in a single API request.
How to validate if a phone number can receive WhatsApp messages
You can validate if a given phone number is linked to a WhatsApp account and can receive messages.
The API provides an endpoint that can validate whether a given phone number exists in WhatsApp or not.
The only requirement is to have at least one WhatsApp number connected to the platform in your current account.
For more details, please check out the API endpoint documentation here.
Before you check if a phone number exists on WhatsApp, you can also validate and normalize the format of a list of phone numbers by using the numbers validator API endpoint. This endpoint only validates the correct E164 format, but it does not check whether the phone number effectively exists on WhatsApp.
Note: The number of WhatsApp check validations is limited per month based on your subscription plan. Please check out the pricing table for more details about the limits.
Looking for more answers? Check out the extended FAQs.
Further useful resources
API Documentation
For more details about the endpoint API, please check the documentation where you will find all the details about the accepted request params, possible success or error responses and ready-to-use code examples in multiple programming languages:
https://app.wassenger.com/docs/#tag/Messages/operation/createMessage