Boost Your Sales With Automated WhatsApp Group Messages

June 25, 2024

Businesses need effective automation tools to connect with customers and drive sales. One powerful yet often overlooked tool is WhatsApp. By creating and managing WhatsApp groups, you can automate the process of sending the relevant information directly to your customers, fostering a sense of community and boosting your sales. In this article, we’ll walk you through how to leverage WhatsApp groups to grow your business with automation combined with Wassenger.

If you want to send messages from code, you can use any programming language that can perform HTTPS requests to the API. You can also debug and test the integration using the API live tester with ready-to-use code examples in 15+ programming languages.

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

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:

  1. Web: go to number’s settings > Groups > Copy the Group WID.
  2. 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:

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

{
  "group": "$GROUP_WID@g.us",
  "message": "This is a sample message sent to a group"
}

Congrats! You can now send automatic messages using the API to groups on WhatsApp.

🤩 🤖 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:

# Examples requires to have installed requests Python package. # Install it by running: pip install requests

import requests

url = "https://api.wassenger.com/v1/messages"

payload = { "group": "1234567890-100000000@g.us", "message": "Sample group message" } headers = { "Content-Type": "application/json", "Token": "ENTER API KEY HERE" }

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

<?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 => "{\"group\":\"1234567890-100000000@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;
}
// Requires to install pecl_http package
// Run: pecl install pecl_http
// More information: https://pecl.php.net/package/pecl_http/3.2.0
$client = new http\Client;
$request = new http\Client\Request;
// Customize the local path of the file to upload
$filepath = '/path/to/image.jpg';
// API key required in order to authenticate the upload
$apikey = '$API_KEY';
// Prepare request
$body = new http\Message\Body;
$body->addForm(null, [
[
'name' => 'file', 
'type' => null, 
'file' => $filename, 
'data' => null
]
]);
$request->setRequestUrl('https://api.wassenger.com/v1/files');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setQuery(new http\QueryString([
'reference' => 'optional-reference-id'
]));
$request->setHeaders([
'Token' => $apikey
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
if($response->getResponseCode() >= 400) {
echo("Invalid request or unsupported file to upload");
} else {
$body = json_decode($response->getBody()->toString());
$file_id = $json[0]['id'];
echo("File uploaded successfully with ID: $file_id");
}
  • C# (RestClient)

// This code requires you to have installed RestSharp package. // Documentation: https://restsharp.dev // Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/messages"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Token", "ENTER API KEY HERE"); request.AddParameter("application/json", "{\"group\":\"1234567890-100000000@g.us\",\"message\":\"Sample group message\"}", ParameterType.RequestBody); IRestResponse response = client.Execute(request);

  • C# (HttpClient)

// This code uses the built-in HttpClient package in the .NET framework. // Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

var client = new HttpClient(); var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri("https://api.wassenger.com/v1/messages"), Headers = { { "Token", "ENTER API KEY HERE" }, }, Content = new StringContent("{\"group\":\"1234567890-100000000@g.us\",\"message\":\"Sample group message\"}") { Headers = { ContentType = new MediaTypeHeaderValue("application/json") } } }; using (var response = await client.SendAsync(request)) { response.EnsureSuccessStatusCode(); var body = await response.Content.ReadAsStringAsync(); Console.WriteLine(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", "ENTER API KEY HERE")
.body("{\"group\":\"1234567890-100000000@g.us\", \"message\":\"Sample group message\"}")
.asString();

🤩 🤖 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**!**

Live testing to send a message to a group via API

Explore our API live tester

FAQs

How to send messages to multiple groups

You just have to send multiple API requests, one per target group.

For instance, if you want to send a message to 10 groups, you should send 10 independent HTTPS requests to the API.

There is no option to send multiple messages in a single API request.

What type of messages can be sent?

You can send different types of messages, including text, images, videos, emojis, audio, gifs, geographic locations and file documents via API.

Check out other tutorials for more information.

Further useful resources

API Documentation

For more details about the endpoint API, please check our documentation. 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

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free