Automate WhatsApp Group Messages Using PHP

March 12, 2025

WhatsApp groups are essential for businesses looking to connect with their teams, customers, or communities. However, manually managing them can be time-consuming. What if you could automate the creation and messaging of WhatsApp groups? With Wassenger and PHP, it’s easy 🤖

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

In this guide, we’ll show you how to:

✅ Create a WhatsApp Group  ✅ Send Messages to a WhatsApp Group  ✅ Automate Group Messaging for Updates and Announcements

Why Automate WhatsApp Group Messaging? 🤔

Manually managing and messaging WhatsApp Groups can be a hassle. Automating the process allows you to:

Save Time — No more sending individual messages to multiple Groups.

Boost Engagement — Keep your teams or customers updated in real-time.

Improve Consistency — Ensure messages are sent at the right time without missing updates.

Scale Communication — Reach more people effortlessly with automated messaging.

📢 Want to get started? Sign up for Wassenger now! 🚀

Requirements

  • Having a WhatsApp number already linked to the platform and online.
  • Group ID (WID) which can be found in two ways:
  1. On your WhatsApp number’s management panel, go to “Groups”. From there you will see the Groups your number has access to.
  2. Using the API, query the available Group in your device for this endpoint.

Prepare the request

Target API URL using the POST method to create a group

http://api.wassenger.com/v1/devices/{deviceId}/groups

Target API URL using the POST method to send messages to a group

https://api.wassenger.com/v1/messages

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Are you a developer?

Explore how to use the code in your browser without installing any software.

Also, you can find different languages you can test on Replit.com:

1. How to Create a WhatsApp Group Using PHP

Creating a WhatsApp Group through Wassenger API is easy. Here’s how to do it in PHP:

Create a Group with PHP (Guzzle)

// This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP. // Install it first following these instructions: // https://docs.guzzlephp.org/en/stable/overview.html#installation

request('POST', 'https://api.wassenger.com/v1/devices/device.id/groups', \[ 'body' => '{"name":"Group name","description":"This is a group sample description","participants":\[{"phone":"+1234567890","admin":true},{"phone":"+1234567890","admin":false}\],"permissions":{"edit":"admins","send":"all","invite":"admins","approval":false}}', 'headers' => \[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', \], \]); echo $response\->getBody(); **Create a Group with PHP (http2)** // This code example 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://mdref.m6w6.name/http append(json\_encode(\[ 'name' => 'Group name', 'description' => 'This is a group sample description', 'participants' => \[ \[ 'phone' => '+1234567890', 'admin' => null \], \[ 'phone' => '+1234567890', 'admin' => null \] \], 'permissions' => \[ 'edit' => 'admins', 'send' => 'all', 'invite' => 'admins', 'approval' => null \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/devices/device.id/groups'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); **Create a Group with PHP (curl)** ```php 'https://api.wassenger.com/v1/devices/{{device.id}}/groups', 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([ 'name' => 'Group name', 'description' => 'This is a group sample description', 'participants' => [ [ 'phone' => '+1234567890', 'admin' => null, ], [ 'phone' => '+1234567890', 'admin' => null, ], ], 'permissions' => [ 'edit' => 'admins', 'send' => 'all', 'invite' => 'admins', 'approval' => null, ], ]), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Token: ENTER API KEY HERE', ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo $response; } ``` ✅ **This creates a new WhatsApp group** named “Customer Support Group” and adds two participants. > *🤩 🤖* [***Wassenger***](https://wassenger.com/) *is a complete communication platform and API solution for WhatsApp.* [***Explore more than 100+ API use cases and automate anything on WhatsApp***](https://wassenger.com/) *by signing up* [*for a free trial and getting started in minutes****!***](https://wassenger.com/register) ### 2\. How to Send Messages to WhatsApp Groups Using PHP Once the group is created, you can send messages to it using the group’s unique ID: **Send Text Message with PHP (Guzzle)** ```php // This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP. // Install it first following these instructions: // https://docs.guzzlephp.org/en/stable/overview.html#installation request('POST', 'https://api.wassenger.com/v1/messages', [ 'body' => '{"group":"group_id@g.us", "message":"Sample group message"}', 'headers' => [ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ], ]); echo $response->getBody(); ``` **Send Text Message with PHP (http2)** ```php // This code example 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://mdref.m6w6.name/http append( json_encode([ 'group' => 'group_id@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' => 'ENTER API KEY HERE', ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` **Send Text Message with PHP (curl)** ```php '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' => 'group_id@g.us', 'message' => 'Sample group message', ]), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Token: ENTER API KEY HERE', ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo $response; } ``` You can also add media to your messages: **Send Media Messages with PHP (Guzzle)** ```php // This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP. // Install it first following these instructions: // https://docs.guzzlephp.org/en/stable/overview.html#installation request('POST', 'https://api.wassenger.com/v1/messages', [ 'body' => '{"group":"group_id@g.us", "message":"This is a caption for an image message", "media":{"url":"https://picsum.photos/seed/picsum/600/400", "viewOnce":false}}', 'headers' => [ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ], ]); echo $response->getBody(); ``` **Send Media Messages with PHP (http2)** ```php // This code example 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://mdref.m6w6.name/http append( json_encode([ 'group' => 'group_id@g.us', 'message' => 'This is a caption for an image message', 'media' => [ 'url' => 'https://picsum.photos/seed/picsum/600/400', 'viewOnce' => null, ], ]) ); $request->setRequestUrl('https://api.wassenger.com/v1/messages'); $request->setRequestMethod('POST'); $request->setBody($body); $request->setHeaders([ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` **Send Media Messages with PHP (curl)** ```php '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' => 'group_id@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: ENTER API KEY HERE', ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo $response; } ``` ✅ **This sends a message to the specified WhatsApp group automatically.** > ***Was this helpful****? Find more examples in our* [***API Live Tester***](https://app.wassenger.com/help/api-tester) *🤖* ### 3\. How to Schedule Messages in a WhatsApp Group Using PHP Scheduling messages allows you to send updates at the perfect time: **Schedule Message with PHP (Guzzle)** ```php // This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP. // Install it first following these instructions: // https://docs.guzzlephp.org/en/stable/overview.html#installation request('POST', 'https://api.wassenger.com/v1/messages', [ 'body' => '{"group":"group_id@g.us", "message":"This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone", "deliverAt":"2025-03-07T10:23:53.810Z"}', 'headers' => [ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ], ]); echo $response->getBody(); ``` **Schedule Message with PHP (http2)** ```php // This code example 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://mdref.m6w6.name/http append( json_encode([ 'group' => 'group_id@g.us', 'message' => 'This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone', 'deliverAt' => '2025-03-07T10:23:53.810Z', ]) ); $request->setRequestUrl('https://api.wassenger.com/v1/messages'); $request->setRequestMethod('POST'); $request->setBody($body); $request->setHeaders([ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` **Schedule Message with PHP (curl)** ```php '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' => 'group_id@g.us', 'message' => 'This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone', 'deliverAt' => '2025-03-07T10:23:53.810Z', ]), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Token: ENTER API KEY HERE', ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo $response; } ``` ✅ **This schedules a message to be sent at a later time automatically.** > ***Was this helpful****? Find more examples in our* [***API Live Tester***](https://app.wassenger.com/help/api-tester) *🤖* ![](/images/blog/automate-whatsapp-group-messages-using-php-02.png) [Try our API-Live tester now](https://app.wassenger.com/help/api-tester)! ### Frequently Asked Questions (FAQ) 🤔 #### 1\. Can I use Wassenger API to remove users from a WhatsApp group? This guide focuses on messaging, but Wassenger API provides group management options, including adding or removing users. 📢 **Need more help?** Visit the [Wassenger Help Center](https://app.wassenger.com/help) for detailed documentation and support! #### 2\. Can I send images, videos, or documents to WhatsApp Groups using Wassenger API? Absolutely! Wassenger API allows you to send multimedia content such as images, videos, PDFs, and more to your WhatsApp groups. #### 3\. How can I check if my message was successfully delivered to a WhatsApp Group? You can use the Wassenger API to retrieve message status updates, ensuring your messages are delivered and read. #### 4\. Can I mention specific users in a WhatsApp group message? Yes! You can mention specific participants by including their phone numbers in the message payload. > *📌* ***Ready to automate your WhatsApp messaging?*** [*Start your free trial today!*](https://app.wassenger.com/register) *🚀* With [**Wassenger**](https://wassenger.com) **and PHP**, you can create, send, and schedule messages to WhatsApp groups effortlessly, making communication smoother and more efficient.

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free