This tutorial will teach you how to send messages to WhatsApp groups using the API.
Effective communication is crucial for keeping teams coordinated, communities engaged, and customer support responsive. Wassenger simplifies this process by enabling smooth management and interaction within WhatsApp groups. With its robust API and automation tools, sharing messages, videos, images, documents, and voice memos is streamlined and efficient.
This guide will walk you through how to use Java to send messages to WhatsApp groups, enhancing your communication and collaboration efforts.
Key Benefits:
- Automate WhatsApp Messages: Save time by automating your WhatsApp communications.
- Better Customer Engagement: Send personalized messages that connect with your customers.
- Cost-Effective Marketing: Lower your costs while boosting your marketing effectiveness.
- Easy Integration: Integrate the Wassenger API with Java smoothly and easily.
🤩 🤖 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 get started in minutes**!**
If you need to send messages from code, you can use any programming language to perform HTTPS API requests. Below is the live API tester with ready-to-use code examples in various programming languages.
Requirements
- Have a WhatsApp number already linked to the platform and online.
- Group WhatsApp ID (WID) that you can find in two ways:
How to obtain the Group WhatsApp ID
You can obtain the Group WhatsApp ID by using one of these methods:
- Web: go to number’s settings > Groups > Copy the Group WID.
- API: query the available groups in your number using this endpoint.
API endpoint
We will use the following API endpoint to send messages to a group:
🖥️ 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.
Steps:
1. Install Unirest: Ensure you have the Unirest package installed.
- Documentation: https://kong.github.io/unirest-java/#requests
- Installation: http://kong.github.io/unirest-java/
2. Prepare the Request: Use Unirest to create and send a POST request with the necessary headers and JSON body.
// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"group\":\"120363029813632@g.us\", \"message\":\"Sample group message\"}")
.asString();
🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!
Do you want to know more? We have all message cases covered!
1. Send text messages with high priority to a group
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"group\":\"123456789000000@g.us\", \"priority\":\"high\", \"message\":\"Hello world! This is a simple test message.\"}")
.asString();
2. Send images to a group chat
// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"group\":\"120363029813632@g.us\", \"message\":\"This is a caption for an image message\", \"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\", \"viewOnce\":false}}")
.asString();
// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"group\":\"120363029813632@g.us\", \"media\":{\"url\":\"https://download.samplelib.com/mp3/sample-9s.mp3\", \"format\":\"ptt\"}}")
.asString();
4. Send a video to a group chat
// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"group\":\"120363029813632@g.us\", \"message\":\"This is a caption for a video message\", \"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\", \"viewOnce\":false}}")
.asString();
5. Send a video to a group chat
// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"group\":\"120363029813632@g.us\", \"media\":{\"url\":\"https://www.africau.edu/images/default/sample.pdf\", \"expiration\":\"30d\"}}")
.asString();
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
From where can I obtain the API code examples?
Please check the API documentation and select the ready-to-use code example in the desired language.
We provide code examples for most common languages and CLI tools, such as JavaScript, Node.js, Python, Ruby, PHP, Java, C#, Swift, Go and more.
Can I use Wassenger for chatbots?
Yes, you can build your chatbot with our API and webhooks. To do so, you need to subscribe to any Platform plan allowing you to implement chatbots on top of the API.
Explore more from our related article here.
How can I validate phone numbers?
You can validate whether a given phone number exists in WhatsApp or not, and therefore can receive messages in WhatsApp, by using the Number exists API endpoint.
Please note you must have at least one WhatsApp number connected to the platform to perform the validation.
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







