How To Send Documents On WhatsApp PDF DOCX XLSX With C NET

January 16, 2025

A Step-by-Step Guide to Sharing Documents with WhatsApp Contacts Using Wassenger

Sharing important documents like PDFs, DOCX files, or XLSX spreadsheets with your WhatsApp contacts can significantly improve collaboration and efficiency. However manually managing these tasks can be time-consuming, especially for companies dealing with multiple contacts and clients.

Enter Wassenger, a powerful CRM designed specifically for WhatsApp messaging. With Wassenger, businesses can effortlessly share documents, automate messaging, and stay connected with their teams and clients in a more organized way. This guide will show you how to leverage Wassenger to send documents seamlessly to WhatsApp contacts, saving you time and enhancing productivity.

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

  • Having a WhatsApp number already linked to the platform and online.
  • Message recipient phone number with international prefix in E164 format. Example: +12345678909. You can validate the phone number here.

Prepare the request

Target API URL using the POST method

https://api.wassenger.com/v1/messages

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

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

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 Documents from URL:

// 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\",\"media\":{\"url\":\"https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611\_sample\_explain.pdf\\",\\"expiration\\":\\"30d\\"}}", ParameterType.RequestBody); IRestResponse response = client.Execute(request);

// 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\",\"media\":{\"url\":\"https://www.africau.edu/images/default/sample.pdf\\",\\"expiration\\":\\"30d\\"}}") { Headers = { ContentType = new MediaTypeHeaderValue("application/json") } } }; using (var response = await client.SendAsync(request)) { response.EnsureSuccessStatusCode(); var body = await response.Content.ReadAsStringAsync(); Console.WriteLine(body); }

Send Documents from an uploaded file:

Replace this expression with the specific value: {{UPLOADED FILE ID}}

// 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\":\"This is a caption for an image message\",\"media\":{\"file\":\"{{UPLOADED FILE ID}}\"}}", ParameterType.RequestBody); IRestResponse response = client.Execute(request);

// 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("{\"phone\":\"+12345678909\",\"message\":\"This is a caption for an image message\",\"media\":{\"file\":\"{{UPLOADED FILE ID}}\"}}") { 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 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

FAQs

How to send messages to multiple contacts

You have to send multiple API requests, one per target contact.

For instance, to send a message to 10 groups, you should send 10 independent HTTPS requests to the API.

There is no option to send multiple messages in a single API request.

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.

Can I schedule bulk messages for a specific time?

Yes, Wassenger allows you to schedule campaigns in advance to send messages at the most convenient time for your audience.

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/Messages

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free