This tutorial will teach you how to send messages to WhatsApp groups using the API.
Whether you’re coordinating a project, building a community, or managing customer support, Wassenger makes it easy to bring people together around common interests and goals. With Wassenger, you can manage and engage your WhatsApp groups, keeping everyone connected and informed.
Wassenger’s powerful API and automation tools enhance the convenience and accessibility of WhatsApp groups, ensuring the best communication and collaboration. Share text messages, videos, images, and voice memos in a dynamic environment for idea exchange and real-time updates. With Wassenger, staying connected with your community has never been more efficient or effective.
We will teach you in a few simple steps:
🤩 🤖 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.
Send automated messages with PHP
- 🔑 Setup: The API key, group ID, and message are stored in variables.
- 🛠️ Client and Request: An
http\Clientand anhttp\Client\Request. - 📝 Body: The message body is created as a JSON object and appended to the request body.
- 🔒 Headers: Headers for
Content-TypeandTokenare added to the request. - 📤 Sending the Request: The request is enqueued and sent. The response is checked for success, and appropriate messages are printed based on the response status.
// Examples requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://pecl.php.net/package/pecl_http/3.2.0
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
json_encode([
'group' => '1203630298136324@g.us',
'message' => 'Sample group message',
])
);
$request->setRequestUrl('https://api.wassenger.com/v1/messages');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
'Content-Type' => 'application/json',
'Token' => 'API_TOKEN_GOES_HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
🤩 🤖 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 PHP (cURL)
- 📲 Dynamic Variables: The API key, group ID, and message are stored in variables.
- ⚙️ cURL Setup:
curl_setopt_arrayis used to configure the cURL options, including the URL, headers, request method, and request body. - 💻 JSON Encoding: The payload is created using
json_encodeto incorporate dynamic variables. - ⚠️ Execution and Error Handling:
curl_execexecutes the request, and any errors are captured withcurl_error. The response or error is then printed.
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'group' => '120363029813632@g.us',
'message' => 'Sample group message',
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: API_TOKEN_GOES_HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
Send images to a group chat with PHP (cURL)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'group' => '120363029813632@g.us',
'message' => 'This is a caption for an image message',
'media' => [
'url' => 'https://picsum.photos/seed/picsum/600/400',
'viewOnce' => null,
],
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: API_TOKEN_GOES_HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
Send videos to a group chat with PHP (cURL)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'group' => '120363029813632@g.us',
'message' => 'This is a caption for a video message',
'media' => [
'url' => 'https://download.samplelib.com/mp4/sample-5s.mp4',
'viewOnce' => null,
],
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: API_TOKEN_GOES_HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
Send audio to a group chat with PHP (cURL)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'group' => '120363029813632@g.us',
'media' => [
'url' => 'https://download.samplelib.com/mp3/sample-9s.mp3',
'format' => 'ptt',
],
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: API_TOKEN_GOES_HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
Send a document to a group chat with PHP (cURL)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'group' => '120363029813632@g.us',
'media' => [
'url' => 'https://www.africau.edu/images/default/sample.pdf',
'expiration' => '30d',
],
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: API_TOKEN_GOES_HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!
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.
🤩 🤖 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!
FAQ
Can I use Wassenger to send marketing messages?
As you may know, WhatsApp has strict policies about sending unsolicited marketing messages, illicit content or spam.
Sending marketing or any unsolicited messages to users is not allowed and you would put your WhatsApp number at a high risk of getting banned.
WhatsApp communication is unsuitable for all business cases, so we recommend designing a legitimate and user-approved communication strategy to avoid problems.
Please read our guidelines with communication best practices and how to prevent getting banned.
How to send messages to multiple phone numbers 📲
You have to send numerous API requests, one per target phone number.
For instance, 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







