# Send Group message

{% hint style="success" %}
**Looking for a full overview of WhatsApp group automation?**\
Check out our guide: [**How to Manage and Automate WhatsApp Groups via API**](https://whapi.cloud/how-to-automate-whatsapp-groups-api) - it includes code examples (Python, Node.js, PHP) and no-code setups using Make, Zapier, and n8n.
{% endhint %}

{% embed url="<https://youtu.be/PlVVoWkDb08>" %}

To send a message to a group you need to know the group ID.

You can get the group ID in several ways:

* When you create a group, the group ID will be specified in the response from the API;
* Get a list of groups (method: <https://whapi.readme.io/reference/getgroups> );
* Get a list of all chats (method: <https://whapi.readme.io/reference/getchats> );

{% hint style="info" %}
The group ID looks like this: <120363194020948049@g.us>. This information cannot be seen in the application or Web version!
{% endhint %}

Once you know the group ID, you can use the method to send any message. For example, a text message

{% embed url="<https://whapi.readme.io/reference/sendmessagetext>" %}
Send private messages or group messages
{% endembed %}

In the `to` parameter you insert the ID of the group you want to send the message to. And in the `body`, the text of the message.

{% hint style="info" %}
All Group API Calls to work with WhatsApp groups: <https://whapi.readme.io/reference/getgroups>
{% endhint %}

#### How to create a group via API

{% embed url="<https://whapi.readme.io/reference/creategroup>" %}

1. Now that your group is up and running, it's time to acquire its unique identifier. Make a quick call to /[getgroup ](https://whapi.readme.io/reference/getgroup)and you'll have what you need.
2. With the identifier in your grasp, you're all set to spread the word! Use POST /[sendmessagetext ](https://whapi.readme.io/reference/sendmessagetext)to shower your group with your initial messages.

### Example usage for WhatsApp API using PHP <a href="#example-usage-for-whatsapp-api-using-php" id="example-usage-for-whatsapp-api-using-php"></a>

Send your first WhatsApp message in group.

For a detailed breakdown of the messaging method, including a comprehensive description of all parameters, additional examples, and options for testing, please visit our Developer Hub at:

{% embed url="<https://whapi.readme.io/reference/sendmessagetext>" %}

```php
const BASE_URL = 'https://gate.whapi.cloud/';
$token = 'bg3FeZJ6jWGw32goN02PRnkKO7k03GtX'; // Specify your channel token here
$data = array (
    'to' => '120363194020948049@g.us',
    'body' => 'Hello, world!',
    'typing_time' => 0,
    'view_once' => true,
);
$data = json_encode($data);
$url = BASE_URL . 'messages/text';
$options = array('http' => array(
    'method'  => 'POST',
    'header' => 'Authorization: Bearer '.$token,
    'content' =>  json_encode($data)
));
$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);
```

* ***'to'*****:** The recipient’s WhatsApp number with international format e.g., 14409416972 or chatID for contact or group e.g <14409416972@s.whatsapp.net> or <120363194020948049@g.us>
* ***'body'*** : Message text.

We offer a convenient service for testing requests and using ready-made code fragments in any programming language. You will only need to transfer the saved API-token and fill in the required parameters:

<figure><img src="https://2417185145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhsdgGmVCG31mEaHyRvxC%2Fuploads%2FznZka2rC6bzvjGMqY6TF%2Fpaste_token_mess.png?alt=media&#x26;token=28239b1f-6b19-4bf7-b16c-b13d57ad9950" alt=""><figcaption><p>Paste your API token and parameters, then copy code snippet</p></figcaption></figure>

Save the PHP script and run it on your server. The specified message will be sent to the specified WhatsApp number. Remember to replace variables with your actual details.

Please note that this is a basic example and doesn't include any error handling. For a production environment, ensure to add appropriate error and exception handling.

Enjoy communicating with your users on a platform they love and use daily! Please don't hesitate to reach out to share your experiences or pose any questions you might have.
