WhatsApp groups have become much more than just tools for collaboration; they are now the perfect space for networking and community building. These groups can bring people together with similar interests who can get advice, and make potential customers of them.
By creating and sharing valuable information (marketing) in these conversations, your potential customers can make their professional networks and gain insights from a wide range of experiences and perspectives but also get interested in your products. Wassenger makes it easy for people to stay informed about your brand or simply as a newsletter about the market your company is in while building strong communities based on mutual support and collaboration.
🤩 🤖 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!
Today, we are going to show you how to send images, videos, documents and voice memos to your groups with Wassenger’s API.
A media file can be any of the following: images (JPEG, PNG, WEBP), videos (MP4, 3GPP), audios (MP3, OGG, MP4, ACC), gifs (MP4) and documents (PDF, PPT, PPTX, DOCX, DOC, ZIP, RAR, other binary types).
If you need to send messages from code, you can use any programming language that can perform HTTPS requests to the API. Below you will find the live API tester with ready-to-use code examples in various programming languages.
Requirements
- To have a WhatsApp number already linked to the platform and online.
- Message recipient phone number with international prefix in E164 format. Example:
+12345678900. Validate the phone number format here.
API endpoints
In this tutorial we will use the following API endpoint:
Breaking news! You can now send media messages in a single API request by passing the remote URL where the file is stored. Click here to test it
Upload the file
To send a file as a multimedia message, in this case, an image file, you should first upload the file to the platform.
You can upload the file by using the following methods using the API:
- Remote URL using JSON with an
urlfield with the publicly accessible URL to download the file (recommended). - Form data (
multipart/form-data) using thefilefield with the file content. - Raw binary data by uploading the file contents as a data stream with the proper file MIME type as Content-Type header, e.g:
image/jpeg,application/pdf.
In this tutorial, we will cover the first two methods of uploading files.
Uploading the file enables the system to validate and store the file just once, avoiding the upload and processing cost every time a media message is delivered, and therefore improving the message delivery speed and simplifying the API integration.
Note that the uploaded file will be stored in the platform for 90 days by default, therefore in many cases you should only upload the file once and that’s it. Optionally, you can also configure how much time the file should be stored in the platform by defining a custom expiration time, for more details check the API documentation. By default, your account has 10GB of files storage capacity in the cloud.
Upload file using a remote URL
You can upload any file to the platform by simply specifying the public URL from where to download the file.
In case the URL is not publicly accessible, it returns a non-valid HTTP status (>=400) or it returns non-binary content, such as HTML or text, the API will return an error.
Target API URL (POST)
https://api.wassenger.com/v1/files
Required HTTPS headers
Content-Type: application/json
Token: $API-TOKEN
Request body in JSON format
{
"url": "https://picsum.photos/seed/picsum/600/400"
}
Alternatively, you can also specify optional fields when uploading the file, such as a custom file expiration time, reference identifier, or a custom filename.
{
"url": "https://picsum.photos/seed/picsum/600/400",
"expiration": "1d",
"filename": "custom-filename.jpg",
"reference": "Optional reference ID"
}
Get the file ID from the API response
If the file is properly uploaded into the platform, the API will return a valid response in JSON format like this:
[
{
"id": "[Redacted ID]",
"format": "native",
"filename": "sample.jpg",
"size": 53697,
"mime": "image/jpeg",
"ext": "jpeg",
"kind": "image",
"sha2": "[Redacted Hash]",
"tags": [],
"status": "active",
"mode": "default",
"createdAt": "2021-05-08T22:49:50.954Z",
"expiresAt": "2021-09-06T22:49:50.949Z"
}
]
Important: From the response JSON you should obtain the id field with a value, for instance06248ed01a7a65946c0701, which represents the unique file ID that we will later use to send the file as a media message in a separate API request.
Upload file using multipart form data
You can upload any file to the platform using the traditional multipart form data mechanism widely used by web browsers to upload different types of content, including files, to a remote server.
Here you can learn more about how multipart form upload works.
Target API URL (POST)
https://api.wassenger.com/v1/files
Required HTTPS headers
Content-Type: multipart/form-data
Token: $API-TOKEN
Request body
Differently from the JSON-based upload, in this case, we need to rely on a more complex mechanism based on the HTTP client we are using that will help us compose the form fields according to the multipart specification.
Depending on the programming language or HTTP client software you are using, the process may vary. For the sake of simplicity, we are going highlight the most popular tools, such as Postman, and popular programming languages.
The core requirement is to define the file field in the form of data, otherwise, the API will return an error as this field is mandatory.
🤩 🤖 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**!**
Upload the file to your web browser
You can manually upload files easily into the platform from the web console without installing any software:
For automated file uploading, please see the alternative options below.
Upload file using cURL
cURL is a popular and useful command-line HTTP client.
You can easily upload files from the command line by using the following command, which path/to/image.jpg should represent the file path you want to upload from your local disk:
curl \
-F file=@path/to/image.jpg \
-H 'Token: $API-TOKEN' \
https://api.wassenger.com/v1/files
Upload file using Postman
Postman is a versatile and handy tool for HTTP testing and debugging.
Following this simple tutorial, you can upload files using Postman, replacing the target URL with the API.
Explore the Postman tutorial here
Upload file using code
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:
# Requires to install requests package:
# Run: pip install requests
import requests
# Customize the local path of the file to upload
filepath = '/path/to/image.jpg'
# API key required in order to authenticate the upload
apikey = '$API_KEY'
# Read file to upload
files = {'file': open(filepath, 'rb')}
# Upload file
response = requests.post('https://api.wassenger.com/v1/files', files=files)
if response.status_code >= 400:
print('Request failed with invalid status:', response.status_code)
else:
json = response.json()
file_id = json[0]['id']
print('File uploaded successfully with ID:', file_id)
// Customize the local path of the file to upload
$filepath = '/path/to/image.jpg';
// API key required in order to authenticate the upload
$apikey = '$API_KEY';
// Upload file
$upload = curl_init();
curl_setopt_array($upload, array(
CURLOPT_URL => 'https://api.wassenger.com/v1/files',
CURLOPT_HTTPHEADER => array(
"Token: $apikey"
),
CURLOPT_POSTFIELDS => array(
'file' => new CURLFile($filepath)
),
CURLOPT_POST => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE
);
$response = curl_exec($upload);
if(curl_errno($ch) {
echo("Request failed");
} else if(curl_getinfo($ch, CURLINFO_HTTP_CODE) >= 400) {
echo("Invalid request or unsupported file to upload");
} else {
$json = json_decode($response, true);
$file_id = $json[0]['id'];
echo("File uploaded successfully with ID: $file_id");
}
// Requires to install pecl_http package
// Run: pecl install pecl_http
// More information: https://pecl.php.net/package/pecl_http/3.2.0
$client = new http\Client;
$request = new http\Client\Request;
// Customize the local path of the file to upload
$filepath = '/path/to/image.jpg';
// API key required in order to authenticate the upload
$apikey = '$API_KEY';
// Prepare request
$body = new http\Message\Body;
$body->addForm(null, [
[
'name' => 'file',
'type' => null,
'file' => $filename,
'data' => null
]
]);
$request->setRequestUrl('https://api.wassenger.com/v1/files');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setQuery(new http\QueryString([
'reference' => 'optional-reference-id'
]));
$request->setHeaders([
'Token' => $apikey
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
if($response->getResponseCode() >= 400) {
echo("Invalid request or unsupported file to upload");
} else {
$body = json_decode($response->getBody()->toString());
$file_id = $json[0]['id'];
echo("File uploaded successfully with ID: $file_id");
}
package main
import(
"net/http"
"os"
"bytes"
"path"
"path/filepath"
"mime/multipart"
"io"
"encoding/json"
)
// API key required in order to authenticate the upload
const apiKey = "$API_KEY"
func main() {
# Customize the local path of the file to upload
fileName:= "path/to/image.jpg"
fileDir, _:= os.Getwd()
filePath:= path.Join(fileDir, fileName)
file, _:= os.Open(filePath)
defer file.Close()
body:= &bytes.Buffer{}
writer:= multipart.NewWriter(body)
part, _:= writer.CreateFormFile("file", filepath.Base(file.Name()))
io.Copy(part, file)
writer.Close()
r, _:= http.NewRequest("POST", "https://api.wassenger.com/v1/files", body)
r.Header.Add("Token", apiKey)
r.Header.Add("Content-Type", writer.FormDataContentType())
client:= &http.Client{Timeout: 90 * time.Second}
response, err:= client.Do(r)
if err != nil {
fmt.Printf("Request failed with an error: %s", err.Error())
return
}
if(response.StatusCode >= 400) {
fmt.Printf("Request failed with response status: %d", response.StatusCode)
return
}
body:= []struct{
Id string `json:"id"`
}{}
defer response.Body.Close()
err:= json.NewDecoder(response.Body).Decode(&body)
if err != nil {
fmt.Printf("Failed to decode JSON: %s", err.Error())
return
}
fileId:= body[0].Id
fmt.Printf("File uploaded successfully with ID:", fileId)
}
RestClient restClient = new RestClient("https://api.wassenger.com");
RestRequest restRequest = new RestRequest("/v1/files");
restRequest.Method = Method.POST;
restRequest.AddHeader("Token", "$API_KEY");
restRequest.AddHeader("Content-Type", "multipart/form-data");
restRequest.AddFile("file", "/path/to/image.jpg");
var response = restClient.Execute(restRequest);
var json = JsonConvert.DeserializeObject(response.Content);
var fileId =(string)json[0]["id"];
Console.WriteLine("File uploaded successfully with ID: {0}", fileId);
require 'net/http/post/multipart'
url = URI.parse('https://api.wassenger.com/v1/files')
File.open("/path/to/image.jpg") do |image|
req = Net::HTTP::Post::Multipart.new url.path, "file" => UploadIO.new(image, "image/jpeg", "image.jpg")
req['Token'] = "API_KEY"
res = Net::HTTP.start(url.host, url.port) do |http|
http.request(req)
end
end
List<File> = Unirest.post("https://api.wassenger.com/v1/files")
.header("Token", "API_KEY")
.field("file", new File("/path/to/image.jpg"))
.getBody()
🤩 🤖 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 the file upload using the API
Send media messages to groups from uploaded file
To do so, you simply need to know the target group chat ID and the uploaded file ID (24 characters hexadecimal) that you can obtain from the uploaded files listed here or from the list of uploaded files via the API.
To send messages to a group, you must be a participant of it with send message permissions. If you are the administrator of the group you will have full permissions to send messages.
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:
# Examples requires to have installed requests Python package.
# Install it by running: pip install requests
import requests
url = "https://api.wassenger.com/v1/messages"
payload = {
"group": "12036302981363@g.us",
"message": "This is a caption for an image message",
"media": { "file": "{{UPLOADED FILE ID}}" }
}
headers = {
"Content-Type": "application/json",
"Token": "API_TOKEN_GOES_HERE"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'group' => '12036302981363@g.us',
'message' => 'This is a caption for an image message',
'media' => [
'file' => '{{UPLOADED FILE ID}}',
],
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: API_TOKEN_GOES_HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
// Examples requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://pecl.php.net/package/pecl_http/3.2.0
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
json_encode([
'group' => '12036302981363@g.us',
'message' => 'This is a caption for an image message',
'media' => [
'file' => '{{UPLOADED FILE ID}}',
],
])
);
$request->setRequestUrl('https://api.wassenger.com/v1/messages');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
'Content-Type' => 'application/json',
'Token' => 'API_TOKEN_GOES_HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
package main
import(
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url:= "https://api.wassenger.com/v1/messages"
payload:= strings.NewReader("{\"group\":\"12036302981363@g.us\", \"message\":\"This is a caption for an image message\", \"media\":{\"file\":\"{{UPLOADED FILE ID}}\"}}")
req, _:= http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Token", "API_TOKEN_GOES_HERE")
res, _:= http.DefaultClient.Do(req)
defer res.Body.Close()
body, _:= io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
- 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\":{\"file\":\"{{UPLOADED FILE ID}}\"}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
require 'uri' require 'net/http'
url = URI("https://api.wassenger.com/v1/messages")
http = Net::HTTP.new(url.host, url.port) http.use_ssl = true
request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request["Token"] = 'API_TOKEN_GOES_HERE' request.body = "{\"group\":\"12036302981363@g.us\",\"message\":\"This is a caption for an image message\",\"media\":{\"file\":\"{{UPLOADED FILE ID}}\"}}"
response = http.request(request) puts response.read_body
// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"group\":\"12036302981363@g.us\", \"message\":\"This is a caption for an image message\", \"media\":{\"file\":\"{{UPLOADED FILE ID}}\"}}")
.asString();
🤩 🤖 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**!**
Send media message from remote URL
You can also send media messages from remote URLs with no need to upload a file to the system.
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:
# Examples requires to have installed requests Python package.
# Install it by running: pip install requests
import requests
url = "https://api.wassenger.com/v1/messages"
payload = {
"group": "12036302981363@g.us",
"message": "This is a caption for an image message",
"media": {
"url": "https://picsum.photos/seed/picsum/600/400",
"viewOnce": False
}
}
headers = {
"Content-Type": "application/json",
"Token": "API_TOKEN_GOES_HERE"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'group' => '12036302981363@g.us',
'message' => 'This is a caption for an image message',
'media' => [
'url' => 'https://picsum.photos/seed/picsum/600/400',
'viewOnce' => null,
],
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: API_TOKEN_GOES_HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
// Examples requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://pecl.php.net/package/pecl_http/3.2.0
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
json_encode([
'group' => '120363029813632@g.us',
'message' => 'This is a caption for an image message',
'media' => [
'url' => 'https://picsum.photos/seed/picsum/600/400',
'viewOnce' => null,
],
])
);
$request->setRequestUrl('https://api.wassenger.com/v1/messages');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
'Content-Type' => 'application/json',
'Token' => 'API_TOKEN_GOES_HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
package main
import(
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url:= "https://api.wassenger.com/v1/messages"
payload:= strings.NewReader("{\"group\":\"120363029813632@g.us\", \"message\":\"This is a caption for an image message\", \"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\", \"viewOnce\":false}}")
req, _:= http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Token", "API_TOKEN_GOES_HERE")
res, _:= http.DefaultClient.Do(req)
defer res.Body.Close()
body, _:= io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
- 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 an image message\", \"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\", \"viewOnce\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
require 'uri' require 'net/http'
url = URI("https://api.wassenger.com/v1/messages")
http = Net::HTTP.new(url.host, url.port) http.use_ssl = true
request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request["Token"] = 'API_TOKEN_GOES_HERE' request.body = "{\"group\":\"12036302981363@g.us\",\"message\":\"This is a caption for an image message\",\"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\\",\\"viewOnce\\":false}}"
response = http.request(request) puts response.read_body
// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"group\":\"12036302981363@g.us\", \"message\":\"This is a caption for an image message\", \"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\", \"viewOnce\":false}}")
.asString()
🤩 🤖 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 the file upload using the API
FAQs
What type of media files can be sent?
You can send images (JPEG, PNG, WEBP), videos (MP4, 3GPP), audios (MP3, OGG, MP4, ACC), gifs (MP4) and documents (PDF, PPT, PPTX, DOCX, DOC, ZIP, RAR, other binary types).
Check out the API documentation for more details.
How to send messages to multiple phone numbers
You just have to send multiple API requests, one per target phone number.
For instance, if you want to send a message to 10 phone numbers, you should send 10 independent HTTPS requests to the API.
There is no option to send multiple messages in a single API request.
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 it does not check whether the phone number effectively exists 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:







