Export WhatsApp Group participants using the API

Wassenger
5 min readJun 27, 2024

Hello! Today we are going to talk about one of the most keen solutions companies willing to accomplish and it is keeping an organized and up-to-date contact list is more important than ever for staying connected and growing your brand. If you’re like many businesses, you probably use WhatsApp groups to share updates, promotions, and valuable information with your customers. But as your groups grow, managing all those contacts can get tricky.

That’s where exporting contacts comes in handy. Imagine being able to easily export all your WhatsApp group contacts and keep them neatly organized. With Wassenger’s API, you can do just that. It’s a game-changer for automating your contact management and making your communication more efficient.

In this article, I’ll show you how to use Wassenger’s WhatsApp API to streamline your contact management process. By the end, you’ll see how simple it is to keep your customer interactions smooth and your marketing efforts on point. Let’s dive in and make your contact list work for you!

If you want to keep your chats and contacts organized 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 get the participants of a group:

Prepare the request

Target API URL using the GET method

https://api.wassenger.com/v1/chat/{deviceId}/chats/{chatWid}/participants

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

Sample JSON response

[
{
"id": "string",
"phone": "string",
"name": "string",
"isSuperAdmin": true,
"isAdmin": true,
"isContact": true
}
]

🤩 🤖 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/chat/{deviceId}/chats/{chatWid}/participants"

payload = {
"size": 250,
"page": 0
}
headers = {
"Content-Type": "application/json",
"Token": "<api token goes here>"
}

response = requests.get(url, json=payload, headers=headers)

print(response.json())
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.wassenger.com/v1/chat/{deviceId}/chats/{chatWid}/participants",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'size' => 250,
'page' => 0
]),
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([
'size' => 250,
'page' => 0
]));
$request->setRequestUrl('https://api.wassenger.com/v1/chat/{deviceId}/chats/{chatWid}/participants');
$request->setRequestMethod('GET');
$request->setBody($body);

$request->setHeaders([
'Content-Type' => 'application/json',
'Token' => '<api token goes here>'
]);

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();
  • 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/chat/{deviceId}/chats/{chatWid}/participants");
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "<api token goes here>");
request.AddParameter("application/json", "{\"size\":250,\"page\":0}", 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

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.wassenger.com/v1/chat/{deviceId}/chats/{chatWid}/participants"),
Headers =
{
{ "Token", "<api token goes here>" },
},
Content = new StringContent("{\"size\":250,\"page\":0}")
{
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.get("https://api.wassenger.com/v1/chat/{deviceId}/chats/{chatWid}/participants")
.header("Content-Type", "application/json")
.header("Token", "<api token goes here>")
.body("{\"size\":250,\"page\":0}")
.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

Is the number of API keys related to the account or the device? If I have two devices do I have two API keys?

Each account has 1 API key, so if you have two devices in the same account you would only have 1 API key.

If you need 2 API keys, you can create 2 different accounts with one device each. There are no additional costs.

What programming languages can I use for the API integration?

You can use any programming language to perform HTTPS requests to remote servers.

This also includes command-line tools like cURL, httpie, and graphical tools like Postman.

How can I validate if a phone number exists in WhatsApp?

You can validate whether a given phone number exists in WhatsApp or not, and therefore can receive messages in WhatsApp, by using the Number exists API endpoint.

Please note you must have at least one WhatsApp number connected to the platform to perform the validation.

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/Chats/operation/getGroupParticipants

--

--

Wassenger
Wassenger

Written by Wassenger

WhatsApp API + Team Chat + CRM + AI Assistant Solution for smart Businesses and Teams. Automate and work more productively with your clients on WhatsApp!

No responses yet