Send messages to WhatsApp groups using C#

This tutorial will teach you how to send messages to WhatsApp groups using the API.

Wassenger
4 min readJul 29, 2024

--

Efficient communication is essential for coordinating projects, building communities, or managing customer support. Wassenger makes this easier by allowing you to manage and engage WhatsApp groups seamlessly. With Wassenger’s API and automation tools, sharing messages, videos, images, documents, and voice memos becomes simple and efficient.

Here’s a guide on how to send messages to WhatsApp groups using C#.

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

If you need to send messages from code, you can use any programming language to perform HTTPS API requests. Below is the live API tester with ready-to-use code examples in various programming languages.

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:

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

Send automated messages with 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", "{\"group\":\"120363029813632@g.us\",\"message\":\"Sample group message\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

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

Send automated messages with 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.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/messages"),
Headers =
{
{ "Token", "API_TOKEN_GOES_HERE" },
},
Content = new StringContent("{\"group\":\"120363029813632@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);
}

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

More examples for group messages with C# (RestClient)

For (httpClient) visit our API Live Tester

Send images to a group chat with 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", "{\"group\":\"12036302981363@g.us\",\"message\":\"This is a caption for an image message\",\"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\",\"viewOnce\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Send audio to a group chat with 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", "{\"group\":\"12036302981363@g.us\",\"media\":{\"url\":\"https://download.samplelib.com/mp3/sample-9s.mp3\",\"format\":\"ptt\"}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Send video to a group chat with 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", "{\"group\":\"120363029813632@g.us\",\"message\":\"This is a caption for a video message\",\"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\",\"viewOnce\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Send documents to a group chat with 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", "{\"group\":\"120363029813632@g.us\",\"media\":{\"url\":\"https://www.africau.edu/images/default/sample.pdf\",\"expiration\":\"30d\"}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

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

FAQ

What type of messages can be sent?

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

Check out other tutorials for more information.

How to validate if a phone number can receive WhatsApp messages

You can validate if a given phone number is linked to a WhatsApp account and can receive messages.

The API provides an endpoint that can validate whether a given phone number exists in WhatsApp or not.

The only requirement is to have at least one WhatsApp number connected to the platform in your current account.

For more details, please check out the API endpoint documentation here.

Before you check if a phone number exists on WhatsApp, you can also validate and normalize the format of a list of phone numbers by using the numbers validator API endpoint. This endpoint only validates the correct E164 format but does not check whether the phone number is effectively on WhatsApp.

Note: The number of WhatsApp check validations is limited per month based on your subscription plan. Please check out the pricing table for more details about the limits.

Looking for more answers? Check out the extended FAQs.

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:

https://app.wassenger.com/docs/#tag/Messages/operation/createMessage

--

--

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