How to send WhatsApp Group Invite links using C#

In this tutorial, we are going to learn how to obtain a WhatsApp Group invitation link and send it to your users who can join your WhatsApp Group using Wassenger API and C#

Wassenger
4 min readOct 14, 2024

--

Sending invite group links via WhatsApp is a great way of expanding your audience on the most popular messaging app with up to 98% open rates. What if you can send them personalized recommendations, answer common questions, and analyze market trends automatically and instantly?

Since WhatsApp has enabled more privacy features for users, nowadays, it is increasingly difficult to invite users as participants in the groups automatically, because if they don’t have your number in their contacts agenda, it will not work because WhatsApp user-enabled privacy may prevent it.

The good news is that there is a solution and we will cover it in this tutorial: you can send a private message to specific users with the group invite link enabling them to join the group as participants.

To achieve this, we need to perform just two tasks using the API:

  1. Obtain the WhatsApp Group invitation link: Note that you must be a participant with invite permissions in the target group to obtain the invite link.
  2. Send the group invite link to the user via private WhatsApp message.

Find below more information and code examples!

🤩 🤖 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 get started in minutes!

Requirements

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 endpoints to send messages to a group:

🖥️ 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.

Get the invitation link using 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/devices/$DEVICE_ID/groups/$GROUP_ID@g.us/invite");
var request = new RestRequest(Method.GET);
request.AddHeader("Token", "ENTER API KEY HERE");
IRestResponse response = client.Execute(request);

Get the invitation link using C# (HttpsClient)

// 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/devices/$DEVICE_ID/groups/$GROUP_ID@g.us/invite"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}

You will get something like:

{
"code": "CPBgYNktDdV0nkjzz9",
"url": "https://chat.whatsapp.com/CPBgYNktDdV0nkjzz9"
}

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

Now, you can share the link with the contacts you want to invite to your group.

Send a message with the given link using 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", "API TOKEN GOES HERE");
request.AddParameter("application/json", "{\"phone\":\"+12345678909\",\"message\":\"Join our offer and discounts WhatsApp group: https://chat.whatsapp.com/CPBgYNktDdV0nkjzz9\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Send a message with the given link using C# (HttpsClient)

// 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.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/messages"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
Content = new StringContent("{\"phone\":\"+1234567890\",\"message\":\"Join our Newsleter group!: https://chat.whatsapp.com/CPBgYNktDdV0nkjzz9\"}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}

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

Try our API-Live tester now

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

--

--

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