Create WhatsApp Groups using the API
In this tutorial, you will learn how to automate a WhatsApp group creation from Wassenger’s API
Hello! Are you ready to elevate your marketing strategy? Discover how creating WhatsApp groups with Wassenger can revolutionize how you connect with customers and boost sales. In this article, we’ll explore why this approach is not only smart but essential for building a community and keeping your audience engaged. Read on to learn how Wassenger simplifies the process and enhances your marketing efforts!
🤩 🤖 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.
- Get your number unique ID given in Wassenger from here.
API endpoint
We will use the following API endpoint to create the group:
Prepare the request
Target API URL using the POST method
https://api.wassenger.com/v1/devices/{deviceId}/groups
Required HTTPS headers > Obtain your API key here
Content-Type: application/json
Token: $API_TOKEN
Use body in JSON format
{
"name": "Group name",
"description": "This is a group sample description",
"participants": [
{
"phone": "+12345678900",
"admin": true
},
{
"phone": "+12345678901",
"admin": false
}
],
"permissions": {
"edit": "admins",
"send": "all",
"invite": "admins",
"approval": false
}
}
🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!
Create a WhatsApp group using the code
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/devices/61b37a069cba0c15d6c/groups"
payload = {
"name": "Group name",
"description": "This is a group sample description",
"participants": [
{
"phone": "+12345678909",
"admin": True
},
{
"phone": "+12345678909",
"admin": False
}
],
"permissions": {
"edit": "admins",
"send": "all",
"invite": "admins",
"approval": False
}
}
headers = {
"Content-Type": "application/json",
"Token": "API_TOKEN_GOES_HERE"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
- PHP (cURL)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c/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' => '+12345678909',
'admin' => null
],
[
'phone' => '+12345678901',
'admin' => null
]
],
'permissions' => [
'edit' => 'admins',
'send' => 'all',
'invite' => 'admins',
'approval' => 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;
}
// 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([
'name' => 'Group name',
'description' => 'This is a group sample description',
'participants' => [
[
'phone' => '+12345678901',
'admin' => null
],
[
'phone' => '+12345678902',
'admin' => null
]
],
'permissions' => [
'edit' => 'admins',
'send' => 'all',
'invite' => 'admins',
'approval' => null
]
]));
$request->setRequestUrl('https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c/groups');
$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();
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c/groups"
payload := strings.NewReader("{\"name\":\"Group name\",\"description\":\"This is a group sample description\",\"participants\":[{\"phone\":\"+12345678902\",\"admin\":true},{\"phone\":\"+12345678901\",\"admin\":false}],\"permissions\":{\"edit\":\"admins\",\"send\":\"all\",\"invite\":\"admins\",\"approval\":false}}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Token", "API_TOKEN_GOES_HERE")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
// 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/devices/61b37a069cba0c15d6c/groups");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "API_TOKEN_GOES_HERE");
request.AddParameter("application/json", "{\"name\":\"Group name\",\"description\":\"This is a group sample description\",\"participants\":[{\"phone\":\"+12345678902\",\"admin\":true},{\"phone\":\"+12345678902\",\"admin\":false}],\"permissions\":{\"edit\":\"admins\",\"send\":\"all\",\"invite\":\"admins\",\"approval\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
require 'uri'
require 'net/http'
url = URI("https://api.wassenger.com/v1/devices/61b37a069cba0c15d6/groups")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["Token"] = 'API_TOKEN_GOES_HERE'
request.body = "{\"name\":\"Group name\",\"description\":\"This is a group sample description\",\"participants\":[{\"phone\":\"+12345678902\",\"admin\":true},{\"phone\":\"+12345678902\",\"admin\":false}],\"permissions\":{\"edit\":\"admins\",\"send\":\"all\",\"invite\":\"admins\",\"approval\":false}}"
response = http.request(request)
puts response.read_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/devices/61b37a069cba0c15d6/groups")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"name\":\"Group name\",\"description\":\"This is a group sample description\",\"participants\":[{\"phone\":\"+12345678902\",\"admin\":true},{\"phone\":\"+12345678902\",\"admin\":false}],\"permissions\":{\"edit\":\"admins\",\"send\":\"all\",\"invite\":\"admins\",\"approval\":false}}")
.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 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.
FAQs
What are the best practices for avoiding failures when creating WhatsApp groups via API?
To minimize failures when creating WhatsApp groups, start with only one or two participants and only add a few at a time. After the group is successfully created, gradually add more members, limiting additions to 10 participants simultaneously using the ‘Add participants’ API endpoint. This approach helps prevent issues, especially if your WhatsApp number is already associated with many active chats.
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: