# Whatsapp API send message С\#

We’ll be using the RestSharp library, a simple REST and HTTP API Client for .NET, to interact with the Whapi.Cloud API.

### Authentication

The first step is to register on the [Whapi.Cloud website](https://panel.whapi.cloud/register) and create an account. It's free and doesn't require you to enter a credit card.

After registration you will immediately have access to a test channel with a small limitation. Wait for it to start (it usually takes about a minute). You will need to connect your phone for Whatsapp automation. It is from the connected phone that messages will be sent.&#x20;

Open your WhatsApp mobile app, navigate to **Settings** -> **Linked devices** -> **Link a device** -> **Scan QR code**

<figure><img src="https://2417185145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhsdgGmVCG31mEaHyRvxC%2Fuploads%2Fpf5TOcIsKhmMv9fcG5ZX%2F00000.png?alt=media&#x26;token=e82d421c-c25e-4858-a18d-e3f8c72c69ab" alt=""><figcaption><p>Pair any number</p></figcaption></figure>

Our service enables you to interact with the API without the need for an uninterrupted phone connection. Operate WhatsApp on up to four paired devices and one mobile device concurrently.

Now save the generated API-Key token on channel page:

<figure><img src="https://2417185145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhsdgGmVCG31mEaHyRvxC%2Fuploads%2F05KGZwXRsJPZ4roIjwHs%2Fchannel-tips.png?alt=media&#x26;token=eba3a04d-0a26-49cc-84a4-fc56260eed1f" alt=""><figcaption><p>Grab your token</p></figcaption></figure>

[<mark style="background-color:yellow;">**Get Started Free**</mark>](https://panel.whapi.cloud/register)

### How to Send WhatsApp API Message using C Sharp <a href="#example-usage-for-whatsapp-api-using-php" id="example-usage-for-whatsapp-api-using-php"></a>

Before diving into the code, you’ll need to set up your development environment. Install the RestSharp package via NuGet Package Manager Console:

```
Install-Package RestSharp
```

We offer a convenient service for testing requests and using ready-made code fragments in any programming language. You will only need to transfer the saved API-token and fill in the required parameters:

{% embed url="<https://whapi.readme.io/reference/sendmessagetext>" %}

<figure><img src="https://2417185145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhsdgGmVCG31mEaHyRvxC%2Fuploads%2FznZka2rC6bzvjGMqY6TF%2Fpaste_token_mess.png?alt=media&#x26;token=28239b1f-6b19-4bf7-b16c-b13d57ad9950" alt=""><figcaption><p>Paste your API token and parameters, then copy code snippet</p></figcaption></figure>

Here’s a concise snippet demonstrating how to send a WhatsApp message using C# and the WhatsApp API:

```csharp
using RestSharp;


var options = new RestClientOptions("https://gate.whapi.cloud/messages/text");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("accept", "application/json");
request.AddHeader("authorization", "Bearer 1On0lX5IB67LBy0M1uc1WuUtaT0X5fkz");
request.AddJsonBody("{\"to\":\"14409416972\",\"body\":\"Hello\"}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```

* ***'to'*****:** The recipient’s WhatsApp number with international format e.g., 14409416972 or chatID for contact or group e.g <14409416972@s.whatsapp.net> or <125001234567890@g.us>
* ***'body'*** : Message text.

Please note that this is a basic example and doesn't include any error handling. For a production environment, ensure to add appropriate error and exception handling.

Make sure to explore the Whapi.Cloud API documentation for more features and possibilities

{% embed url="<https://whapi.readme.io/reference/sendmessagetext>" %}

Moreover, you can interact dynamically with emoji messages by quoting, marking them as read, or simulating real-time typing.&#x20;

Furthermore, you can efficiently manage your groups by changing avatars, renaming them, inviting new members, or blocking unwanted users.

### Send Media Message

{% embed url="<https://whapi.readme.io/reference/sendmessageimage>" %}

Please don't hesitate to reach out to share your experiences or pose any questions you might have.

[<mark style="background-color:yellow;">**Get Started Free**</mark>](https://panel.whapi.cloud/register)

### Send Document <a href="#send-document" id="send-document"></a>

{% embed url="<https://whapi.readme.io/reference/sendmessagedocument>" %}

### Send Audio <a href="#send-audio" id="send-audio"></a>

{% embed url="<https://whapi.readme.io/reference/sendmessageaudio>" %}

### Send Voice <a href="#send-voice" id="send-voice"></a>

You can Send a ppt audio recording to the phone number or group, But WhatsApp is sensitive to this extension, you need to be in OGG format and the **codecs** should be the **opus**. Our API has an automatic video and audio converter for the necessary codecs compatible with WhatsApp. For more information, you can check out this [article](https://support.whapi.cloud/help-desk/sending/overview-of-other-methods-for-sending/send-voice-message).

{% embed url="<https://whapi.readme.io/reference/sendmessagevoice>" %}

### Send Video <a href="#send-video" id="send-video"></a>

{% embed url="<https://whapi.readme.io/reference/sendmessagevideo>" %}

### Send GIF

{% embed url="<https://whapi.readme.io/reference/sendmessagegif>" %}

### Send Contact <a href="#send-contact" id="send-contact"></a>

{% embed url="<https://whapi.readme.io/reference/sendmessagecontact>" %}

### Send Contact List

{% embed url="<https://whapi.readme.io/reference/sendmessagecontactlist>" %}

### Send Location <a href="#send-location" id="send-location"></a>

{% embed url="<https://whapi.readme.io/reference/sendmessagelocation>" %}

### Send Sticker

{% embed url="<https://whapi.readme.io/reference/sendmessagesticker>" %}
