Following our WhatsApp group tips articles series with Wassenger’s API, we will show you how to manage WhatsApp groups easily with simple code with the most popular code languages. Look at our live API tester and discover what Wassenger can do for your business.
- Learn how to create a group from our API here
- Learn how to add and remove participants from a group here
🤩 🤖 Discover all our new features here or 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 manage group chats:
Prepare the request
Promote/demote participants
Target API URL using the PATCH method to promote/demote participants
Change the value "admin": true
or "admin": false
to declare if the participant is demoted or promoted.
{
"participants": [
{
"phone": "+12345678901",
"admin": true
},
{
"phone": "+12345678902",
"admin": true
}
]
}
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/$DEVICE/groups/$GROUP_ID@g.us/participants"
payload = { "participants": [
{
"phone": "+12345678909",
"admin": True
},
{
"phone": "+12345678901",
"admin": False
}
] }
headers = {
"Content-Type": "application/json",
"Token": "API_TOKEN_GOES_HERE"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.wassenger.com/v1/devices/$DEVICE/groups/$GROUP_ID@g.us/participants",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'participants' => [
[
'phone' => '+12345678902',
'admin' => null
],
[
'phone' => '+12345678901',
'admin' => 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([
'participants' => [
[
'phone' => '+12345678902',
'admin' => null
],
[
'phone' => '+12345678902',
'admin' => null
]
]
]));
$request->setRequestUrl('https://api.wassenger.com/v1/devices/$DEVICE/groups/1203630298136@g.us/participants');
$request->setRequestMethod('PATCH');
$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/$DEVICE/groups/1203630298136@g.us/participants"
payload := strings.NewReader("{\"participants\":[{\"phone\":\"+12345678902\",\"admin\":true},{\"phone\":\"+12345678903\",\"admin\":false}]}")
req, _ := http.NewRequest("PATCH", 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/$DEVICE/groups/12036302981363@g.us/participants");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "API_TOKEN_GOES_HERE");
request.AddParameter("application/json", "{\"participants\":[{\"phone\":\"+12345678902\",\"admin\":true},{\"phone\":\"+12345678901\",\"admin\":false}]}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
require 'uri'
require 'net/http'
url = URI("https://api.wassenger.com/v1/devices/$DEVICE/groups/12036302981363@g.us/participants")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Content-Type"] = 'application/json'
request["Token"] = 'API_TOKEN_GOES_HERE'
request.body = "{\"participants\":[{\"phone\":\"+12345678902\",\"admin\":true},{\"phone\":\"+12345678902\",\"admin\":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.patch("https://api.wassenger.com/v1/devices/$DEVICE/groups/12036302981363@g.us/participants")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"participants\":[{\"phone\":\"+12345678902\",\"admin\":true},{\"phone\":\"+12345678903\",\"admin\":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!
Get group invite code
Target API URL using the GET method to get group invite code and URL to share with new participants.
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/61b37a069cba0c15d6/groups/12036302981363@g.us/invite"
headers = {"Token": "API_TOKEN_GOES_HERE"}
response = requests.get(url, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c/groups/12036302981363@g.us/invite",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"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;
$request->setRequestUrl('https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c8/groups/120363029813638@g.us/invite');
$request->setRequestMethod('GET');
$request->setHeaders([
'Token' => 'API_TOKEN_GOES_HERE'
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.wassenger.com/v1/devices/61b37a069cba0c15d7/groups/12036302981363@g.us/invite"
req, _ := http.NewRequest("GET", url, nil)
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/61b37a069cba0c15d7/groups/12036302981363@g.us/invite");
var request = new RestRequest(Method.GET);
request.AddHeader("Token", "API_TOKEN_GOES_HERE");
IRestResponse response = client.Execute(request);
require 'uri'
require 'net/http'
url = URI("https://api.wassenger.com/v1/devices/61b37a069cba0c15d7/groups/12036302981363@g.us/invite")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Token"] = 'API_TOKEN_GOES_HERE'
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.get("https://api.wassenger.com/v1/devices/61b37a069cba0c15d7/groups/12036302981363@g.us/invite")
.header("Token", "API_TOKEN_GOES_HERE")
.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!
Revoke group invite
Target API URL using the DELETE method to revoke group invite 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/1203630298136@g.us/invite"
headers = {"Token": "API_TOKEN_GOES_HERE"}
response = requests.delete(url, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c89/groups/12036302981363@g.us/invite",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
"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;
$request->setRequestUrl('https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c89/groups/120363029813632@g.us/invite');
$request->setRequestMethod('DELETE');
$request->setHeaders([
'Token' => 'API_TOKEN_GOES_HERE'
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c/groups/1203630298136@g.us/invite"
req, _ := http.NewRequest("DELETE", url, nil)
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/61b37a069cba0c15d7/groups/12036302981363@g.us/invite");
var request = new RestRequest(Method.DELETE);
request.AddHeader("Token", "API_TOKEN_GOES_HERE");
IRestResponse response = client.Execute(request);
require 'uri'
require 'net/http'
url = URI("https://api.wassenger.com/v1/devices/61b37a069cba0c15d7/groups/1203630298188@g.us/invite")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["Token"] = 'API_TOKEN_GOES_HERE'
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.delete("https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c/groups/12036302981363@g.us/invite")
.header("Token", "API_TOKEN_GOES_HERE")
.asString();
🖥️ 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.
Update group information
Target API URL using the PATCH method to update group name, description and/or publication/edit permissions for existing participants.
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/1203630298136@g.us"
payload = {
"name": "New group name",
"description": "This is a new group sample description",
"ephemeral": "7d",
"permissions": {
"edit": "admins",
"send": "all",
"invite": "all",
"approval": False
}
}
headers = {
"Content-Type": "application/json",
"Token": "API_TOKEN_GOES_HERE"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c/groups/1203630298136@g.us",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'New group name',
'description' => 'This is a new group sample description',
'ephemeral' => '7d',
'permissions' => [
'edit' => 'admins',
'send' => 'all',
'invite' => 'all',
'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' => 'New group name',
'description' => 'This is a new group sample description',
'ephemeral' => '7d',
'permissions' => [
'edit' => 'admins',
'send' => 'all',
'invite' => 'all',
'approval' => null
]
]));
$request->setRequestUrl('https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c8/groups/120363029813@g.us');
$request->setRequestMethod('PATCH');
$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/1203630298136@g.us"
payload := strings.NewReader("{\"name\":\"New group name\",\"description\":\"This is a new group sample description\",\"ephemeral\":\"7d\",\"permissions\":{\"edit\":\"admins\",\"send\":\"all\",\"invite\":\"all\",\"approval\":false}}")
req, _ := http.NewRequest("PATCH", 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/61b37a069cba0c15d6/groups/1203630298136@g.us");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "API_TOKEN_GOES_HERE");
request.AddParameter("application/json", "{\"name\":\"New group name\",\"description\":\"This is a new group sample description\",\"ephemeral\":\"7d\",\"permissions\":{\"edit\":\"admins\",\"send\":\"all\",\"invite\":\"all\",\"approval\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
require 'uri'
require 'net/http'
url = URI("https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c/groups/120363029813@g.us")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Content-Type"] = 'application/json'
request["Token"] = 'API_TOKEN_GOES_HERE'
request.body = "{\"name\":\"New group name\",\"description\":\"This is a new group sample description\",\"ephemeral\":\"7d\",\"permissions\":{\"edit\":\"admins\",\"send\":\"all\",\"invite\":\"all\",\"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.patch("https://api.wassenger.com/v1/devices/61b37a069cba0c15d6c8/groups/1203630298136@g.us")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"name\":\"New group name\",\"description\":\"This is a new group sample description\",\"ephemeral\":\"7d\",\"permissions\":{\"edit\":\"admins\",\"send\":\"all\",\"invite\":\"all\",\"approval\":false}}")
.asString();
🤩 🤖 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
How can I manage contacts in a group?
You just have to send multiple API requests, one per target group.
For instance, if you want to update 10 groups, you should send 10 independent HTTPS requests to the API and one per method (POST, PATCH or DELETE).
There is no option to manage different groups in a single API request.
How many contacts I can manage at once?
To prevent processing issues or errors, it is not recommended to manage more than 10 participants at a time per API request (add, delete, promote or demote).
Further useful resources
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.