Send Messages And Manage WhatsApp Groups Using C NET

December 16, 2024

Today, you’ll learn everything you need to know to send messages to WhatsApp groups 📲 and keep your audience engaged and up-to-date! 🚀

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

This will allow us to perform the following deliveries

  • Send text messages
  • Send scheduled text messages
  • Send a file
  • Send images
  • Send videos
  • Send polls
  • Send Scheduled polls
  • Send votes to an existing group poll
  • Send meeting event video call
  • Mention group participants in a message

Manage groups

  • Create a group
  • Get a list of available groups
  • Update group information and permissions
  • Update group image
  • Get group participants
  • Add participants from a group
  • Remove participants from a group
  • Approve all pending group members
  • Reject all pending group members
  • Get group invite code and URL

Requirements

  • Having a WhatsApp number already linked to the platform and online.
  • Channel WhatsApp ID (WID) that you can find in two ways:
  1. On your WhatsApp number’s management panel, go to “Groups”. From there you will see the channels your number has access to.
  2. By using the API, query the available channels in your device for this endpoint.

API endpoint

In this tutorial we will use the following API endpoint:

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:

Send text messages using C# (RestClient)

// This code requires you to have installed RestSharp package. // Documentation: https://restsharp.dev // Installation: https://www.nuget.org/packages/RestSharp

using System; using RestSharp;

class Program { static void Main(string[] args) { // Define API details string apiUrl = "https://api.wassenger.com/v1/messages"; string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key

    // Define the group ID and message
    string groupId = "$group\_id@g.us@g.us"; // Replace with your group ID
    string message = "Sample group message";

    // Create the RestSharp client
    var client = new RestClient(apiUrl);

    // Create the POST request
    var request = new RestRequest(Method.POST);

    // Add headers
    request.AddHeader("Authorization", $"Bearer {apiKey}");
    request.AddHeader("Content-Type", "application/json");

    // Add the JSON payload
    request.AddJsonBody(new
    {
        group = groupId,
        message = message
    });

    // Execute the request and get the response
    IRestResponse response = client.Execute(request);

    // Handle the response
    if (response.IsSuccessful)
    {
        Console.WriteLine("Message sent successfully!");
    }
    else
    {
        Console.WriteLine($"Failed to send message. Status: {response.StatusCode}");
        Console.WriteLine($"Error: {response.Content}");
    }
}

}

Send text messages using 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; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks;

class Program { static async Task Main(string[] args) { // Define API details string apiUrl = "https://api.wassenger.com/v1/messages"; string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key

    // Define the group ID and message
    string groupId = "$group\_id@g.us"; // Replace with your group ID
    string message = "Sample group message";

    // Create the HTTP client
    using (var client = new HttpClient())
    {
        // Create the JSON payload
        var payload = new
        {
            group = groupId,
            message = message
        };

        // Serialize the payload to JSON
        string jsonPayload = System.Text.Json.JsonSerializer.Serialize(payload);

        // Create the HTTP request
        var request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri(apiUrl),
            Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
        };

        // Add headers
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
        request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        // Send the request
        var response = await client.SendAsync(request);

        // Handle the response
        if (response.IsSuccessStatusCode)
        {
            Console.WriteLine("Message sent successfully!");
        }
        else
        {
            Console.WriteLine($"Failed to send message. Status: {response.StatusCode}");
            string responseBody = await response.Content.ReadAsStringAsync();
            Console.WriteLine($"Error: {responseBody}");
        }
    }
}

}

Send scheduled text messages using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// Define API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Define the group ID, message, and schedule time
string groupId = "$group_id@g.us"; // Replace with your group ID
string message = "This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone";
string deliverAt = "2024-12-17T11:33:47.255Z"; // Replace with the desired delivery time
// Create the RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
message = message, 
deliverAt = deliverAt
});
// Execute the request and get the response
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Scheduled message created successfully!");
}
else
{
Console.WriteLine($"Failed to create scheduled message.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Send scheduled text messages using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Define API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Define the group ID, message, and schedule time
string groupId = "$group_id@g.us"; // Replace with your group ID
string message = "This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone";
string deliverAt = "2024-12-17T11:33:47.255Z"; // Replace with the desired delivery time
// Create the HTTP client
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
message = message, 
deliverAt = deliverAt
};
// Serialize the payload to JSON
string jsonPayload = System.Text.Json.JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Scheduled message created successfully!");
}
else
{
Console.WriteLine($"Failed to create scheduled message.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

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

Send a file to WhatsApp groups using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Group ID and file details
string groupId = "$group_id@g.us"; // Replace with your group ID
string fileUrl = "https://www.africau.edu/images/default/sample.pdf";
string fileExpiration = "30d";
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
media = new
{
url = fileUrl, 
expiration = fileExpiration
}
});
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("File sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send file to group.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Send a file to WhatsApp groups using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Group ID and file details
string groupId = "$group_id@g.us"; // Replace with your group ID
string fileUrl = "https://www.africau.edu/images/default/sample.pdf";
string fileExpiration = "30d";
// Create HttpClient
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
media = new
{
url = fileUrl, 
expiration = fileExpiration
}
};
// Serialize the payload to JSON
string jsonPayload = JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("File sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send file to group.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

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

Send an image to groups using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Group ID and image details
string groupId = "$group_id@g.us"; // Replace with your group ID
string imageUrl = "https://picsum.photos/seed/picsum/600/400";
string caption = "This is a caption for an image message";
bool viewOnce = false;
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
message = caption, 
media = new
{
url = imageUrl, 
viewOnce = viewOnce
}
});
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Image sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send image to group.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Send an image to groups using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Group ID and image details
string groupId = "$group_id@g.us"; // Replace with your group ID
string imageUrl = "https://picsum.photos/seed/picsum/600/400";
string caption = "This is a caption for an image message";
bool viewOnce = false;
// Create HttpClient
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
message = caption, 
media = new
{
url = imageUrl, 
viewOnce = viewOnce
}
};
// Serialize the payload to JSON
string jsonPayload = JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Image sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send image to group.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Send a video to groups using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Group ID and video details
string groupId = "$group_id@g.us"; // Replace with your group ID
string videoUrl = "https://download.samplelib.com/mp4/sample-5s.mp4";
string caption = "This is a caption for a video message";
bool viewOnce = false;
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
message = caption, 
media = new
{
url = videoUrl, 
viewOnce = viewOnce
}
});
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Video sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send video to group.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Send a video to groups using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Group ID and video details
string groupId = "$group_id@g.us"; // Replace with your group ID
string videoUrl = "https://download.samplelib.com/mp4/sample-5s.mp4";
string caption = "This is a caption for a video message";
bool viewOnce = false;
// Create HttpClient
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
message = caption, 
media = new
{
url = videoUrl, 
viewOnce = viewOnce
}
};
// Serialize the payload to JSON
string jsonPayload = JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Video sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send video to group.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Send a polls using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Group ID and poll details
string groupId = "$group_id@g.us"; // Replace with your group ID
string pollName = "Vote for your favorite color";
string[] options = { "Red", "Green", "Blue", "Yellow", "Grey", "Black", "Orange", "Purple", "White" };
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
poll = new
{
name = pollName, 
options = options
}
});
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Poll sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send poll to group.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Send a poll using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Group ID and poll details
string groupId = "$group_id@g.us"; // Replace with your group ID
string pollName = "Vote for your favorite color";
string[] options = { "Red", "Green", "Blue", "Yellow", "Grey", "Black", "Orange", "Purple", "White" };
// Create HttpClient
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
poll = new
{
name = pollName, 
options = options
}
};
// Serialize the payload to JSON
string jsonPayload = JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Poll sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send poll to group.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

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

Send a scheduled poll using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Poll details
string groupId = "$group_id@g.us"; // Replace with your group ID
string deliverAt = "2024-12-17T11:33:47.255Z"; // Scheduled delivery time in ISO 8601 format
string pollName = "Vote for your favorite color";
string[] options = { "Red", "Green", "Blue", "Yellow", "Grey", "Black", "Orange", "Purple", "White" };
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
deliverAt = deliverAt, 
poll = new
{
name = pollName, 
options = options
}
});
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Scheduled poll sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send scheduled poll to group.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Send a scheduled poll using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Poll details
string groupId = "$group_id@g.us"; // Replace with your group ID
string deliverAt = "2024-12-17T11:33:47.255Z"; // Scheduled delivery time in ISO 8601 format
string pollName = "Vote for your favorite color";
string[] options = { "Red", "Green", "Blue", "Yellow", "Grey", "Black", "Orange", "Purple", "White" };
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
deliverAt = deliverAt, 
poll = new
{
name = pollName, 
options = options
}
};
// Serialize payload to JSON
string jsonPayload = JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Scheduled poll sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send scheduled poll to group.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

**Send votes to an existing group poll using C# (RestClient) **You should replace the following expressions with an actual value:

{{POLL_MESSAGE_ID}} : Replace this expression with the specific value

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Poll details
string groupId = "$group_id@g.us"; // Replace with your group ID
string deliverAt = "2024-12-17T11:33:47.255Z"; // Scheduled delivery time in ISO 8601 format
string pollName = "Vote for your favorite color";
string[] options = { "Red", "Green", "Blue", "Yellow", "Grey", "Black", "Orange", "Purple", "White" };
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
deliverAt = deliverAt, 
poll = new
{
name = pollName, 
options = options
}
});
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Scheduled poll sent to group successfully!");
}
else
{
Console.WriteLine($"Failed to send scheduled poll to group.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

**Send votes to an existing group poll using C# (HttpClient) **You should replace the following expressions with an actual value:

{{POLL_MESSAGE_ID}} : Replace this expression with the specific value

// 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Voting details
string groupId = "$group_id@g.us"; // Replace with your group ID
string pollMessageId = "{{POLL_MESSAGE_ID}}"; // Replace with the poll message ID
var options = new[]
{
new { value = "White" }, // Vote by value
new { id = 3 } // Vote by option ID
};
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
vote = new
{
poll = pollMessageId, 
options = options
}
};
// Serialize payload to JSON
string jsonPayload = JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Vote sent successfully!");
}
else
{
Console.WriteLine($"Failed to send vote.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Send meeting event video call to a group using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Event details
string groupId = "$group_id@g.us"; // Replace with your group ID
var eventDetails = new
{
name = "Sales meeting", 
description = "This is a sample meeting event description, up to 2048 characters", 
location = "London HQ", 
call = "video", 
date = "2024-12-16T11:43:47.255Z"
};
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
event = eventDetails
});
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Event message sent successfully!");
}
else
{
Console.WriteLine($"Failed to send event message.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Send meeting event video call to a group using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Event details
string groupId = "$group_id@g.us"; // Replace with your group ID
var eventDetails = new
{
name = "Sales meeting", 
description = "This is a sample meeting event description, up to 2048 characters", 
location = "London HQ", 
call = "video", 
date = "2024-12-16T11:43:47.255Z"
};
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
event = eventDetails
};
// Serialize payload to JSON
string jsonPayload = JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Event message sent successfully!");
}
else
{
Console.WriteLine($"Failed to send event message.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Mention group participants in a message using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Message details
string groupId = "$group_id@g.us"; // Replace with your group ID
string mentionedNumber = "1234567890"; // Replace with the group member's phone number
string messageText = $"This is a message mentioning a group participant @{mentionedNumber}";
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
request.AddJsonBody(new
{
group = groupId, 
message = messageText
});
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Message sent successfully!");
}
else
{
Console.WriteLine($"Failed to send message.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Mention group participants in a message using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/messages";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Message details
string groupId = "$group_id@g.us"; // Replace with your group ID
string mentionedNumber = "1234567890"; // Replace with the group member's phone number
string messageText = $"This is a message mentioning a group participant @{mentionedNumber}";
using(var client = new HttpClient())
{
// Create the JSON payload
var payload = new
{
group = groupId, 
message = messageText
};
// Serialize payload to JSON
string jsonPayload = JsonSerializer.Serialize(payload);
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Message sent successfully!");
}
else
{
Console.WriteLine($"Failed to send message.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

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

Manage Groups

Create a WhatsApp group using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddHeader("Content-Type", "application/json");
// Add the JSON payload
var payload = new
{
name = "Group name", 
description = "This is a group sample description", 
participants = new[]
{
new { phone = "+1234567890", admin = true }, 
new { phone = "+0987654321", admin = false }
}, 
permissions = new
{
edit = "admins", 
send = "all", 
invite = "admins", 
approval = false
}
};
request.AddJsonBody(payload);
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Group created successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to create group.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Create a WhatsApp group using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups";
string apiKey = "ENTER API KEY HERE"; // Replace with your API key
// Group details
var groupDetails = new
{
name = "Group name", 
description = "This is a group sample description", 
participants = new[]
{
new { phone = "+1234567890", admin = true }, 
new { phone = "+0987654321", admin = false }
}, 
permissions = new
{
edit = "admins", 
send = "all", 
invite = "admins", 
approval = false
}
};
// Serialize group details to JSON
string jsonPayload = JsonSerializer.Serialize(groupDetails);
using(var client = new HttpClient())
{
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Group created successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to create group.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Get a list of available group chats using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the GET request
var request = new RestRequest(Method.GET);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Groups retrieved successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to retrieve groups.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Get a list of available group chats using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API details
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
using(var client = new HttpClient())
{
// Create the HTTP request
var request = new HttpRequestMessage
{
Method = HttpMethod.Get, 
RequestUri = new Uri(apiUrl)
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Groups retrieved successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to retrieve groups.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

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

Update group information and permissions using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Payload data
string jsonPayload = @"
{
""name"": ""New group name"", 
""description"": ""This is a new group sample description"", 
""ephemeral"": ""7d"", 
""permissions"": {
""edit"": ""admins"", 
""send"": ""all"", 
""invite"": ""all"", 
""approval"": false
}
}";
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the PATCH request
var request = new RestRequest(Method.PATCH);
// Add headers
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Add the payload
request.AddParameter("application/json", jsonPayload, ParameterType.RequestBody);
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Group info updated successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to update group info.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Update group information and permissions using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Payload data
string jsonPayload = @"
{
""name"": ""New group name"", 
""description"": ""This is a new group sample description"", 
""ephemeral"": ""7d"", 
""permissions"": {
""edit"": ""admins"", 
""send"": ""all"", 
""invite"": ""all"", 
""approval"": false
}
}";
using(var client = new HttpClient())
{
// Create the request
var request = new HttpRequestMessage
{
Method = HttpMethod.Patch, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Group info updated successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to update group info.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Update group image using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/image";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Payload data
string jsonPayload = @"
{
""url"": ""https://picsum.photos/200""
}";
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the PUT request
var request = new RestRequest(Method.PUT);
// Add headers
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Add the payload
request.AddParameter("application/json", jsonPayload, ParameterType.RequestBody);
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Group image updated successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to update group image.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Update group image using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/image";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Payload data
string jsonPayload = @"
{
""url"": ""https://picsum.photos/200""
}";
using(var client = new HttpClient())
{
// Create the request
var request = new HttpRequestMessage
{
Method = HttpMethod.Put, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Group image updated successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to update group image.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Get group participants using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/chat/{{device.id}}/chats/$group_id@g.us/participants";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the GET request
var request = new RestRequest(Method.GET);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Group participants retrieved successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to retrieve group participants.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

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

Get group participants using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/chat/{{device.id}}/chats/$group_id@g.us/participants";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
using(var client = new HttpClient())
{
// Create the GET request
var request = new HttpRequestMessage
{
Method = HttpMethod.Get, 
RequestUri = new Uri(apiUrl)
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Group participants retrieved successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to retrieve group participants.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Add participants to a group using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/participants";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Request body
string jsonBody = @"
{
""participants"": [
{ ""phone"": ""+1234567890"", ""admin"": true }, 
{ ""phone"": ""+1234567890"", ""admin"": false }
]
}";
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Add the JSON body
request.AddParameter("application/json", jsonBody, ParameterType.RequestBody);
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Participants added successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to add participants.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Add participants to a group using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/participants";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Request body
string jsonBody = @"
{
""participants"": [
{ ""phone"": ""+1234567890"", ""admin"": true }, 
{ ""phone"": ""+1234567890"", ""admin"": false }
]
}";
using(var client = new HttpClient())
{
// Create the POST request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonBody, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Participants added successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to add participants.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Remove participants from a group using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/participants";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Request body - List of participants to be removed
string jsonBody = @"[\""+1234567890\"", \""+1234567890\"]";
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the DELETE request
var request = new RestRequest(Method.DELETE);
// Add headers
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Add the JSON body
request.AddParameter("application/json", jsonBody, ParameterType.RequestBody);
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Participants removed successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to remove participants.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Remove participants from a group using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/participants";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Request body - List of participants to be removed
string jsonBody = @"[\""+1234567890\"", \""+1234567890\"]";
using(var client = new HttpClient())
{
// Create the DELETE request
var request = new HttpRequestMessage
{
Method = HttpMethod.Delete, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonBody, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Participants removed successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to remove participants.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

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

Approve all pending group members using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/members";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Request body to approve all pending members
string jsonBody = "{\"all\":true}";
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the POST request
var request = new RestRequest(Method.POST);
// Add headers
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Add the JSON body
request.AddParameter("application/json", jsonBody, ParameterType.RequestBody);
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Pending members approved successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to approve pending members.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Approve all pending group members using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$device_id@g.us/members";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Request body to approve all pending members
string jsonBody = "{\"all\":true}";
using(var client = new HttpClient())
{
// Create the POST request
var request = new HttpRequestMessage
{
Method = HttpMethod.Post, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonBody, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Pending members approved successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to approve pending members.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Reject all pending group members using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/members";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Request body to reject all pending members
string jsonBody = "{\"all\":true}";
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the DELETE request
var request = new RestRequest(Method.DELETE);
// Add headers
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Add the JSON body
request.AddParameter("application/json", jsonBody, ParameterType.RequestBody);
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("Pending members rejected successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to reject pending members.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Reject all pending group members using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/members";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Request body to reject all pending members
string jsonBody = "{\"all\":true}";
using(var client = new HttpClient())
{
// Create the DELETE request
var request = new HttpRequestMessage
{
Method = HttpMethod.Delete, 
RequestUri = new Uri(apiUrl), 
Content = new StringContent(jsonBody, Encoding.UTF8, "application/json")
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Pending members rejected successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to reject pending members.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Get group invite code and URL using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/invite";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
// Create RestSharp client
var client = new RestClient(apiUrl);
// Create the GET request
var request = new RestRequest(Method.GET);
// Add headers
request.AddHeader("Authorization", $"Bearer {apiKey}");
// Execute the request
IRestResponse response = client.Execute(request);
// Handle the response
if(response.IsSuccessful)
{
Console.WriteLine("URL Invite Code retrieved successfully!");
Console.WriteLine($"Response: {response.Content}");
}
else
{
Console.WriteLine($"Failed to retrieve URL Invite Code.Status: {response.StatusCode}");
Console.WriteLine($"Error: {response.Content}");
}
}
}

Get group invite code and URL using 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;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// API endpoint
string apiUrl = "https://api.wassenger.com/v1/devices/{{device.id}}/groups/$group_id@g.us/invite";
string apiKey = "ENTER API KEY HERE"; // Replace with your actual API key
using(var client = new HttpClient())
{
// Create the GET request
var request = new HttpRequestMessage
{
Method = HttpMethod.Get, 
RequestUri = new Uri(apiUrl)
};
// Add headers
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// Send the request
var response = await client.SendAsync(request);
// Handle the response
if(response.IsSuccessStatusCode)
{
Console.WriteLine("URL Invite Code retrieved successfully!");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
Console.WriteLine($"Failed to retrieve URL Invite Code.Status: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error: {responseBody}");
}
}
}
}

Live API testing

You can live-test and play with the API directly from your browser.

Once you are done testing, you can 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 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!

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.

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.

Further useful resources

API Documentation

For more details about the endpoint API, please check the documentation, which contains information about the accepted request parameters, possible success or error responses, and ready-to-use code examples in multiple programming languages.

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

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free