Learn how to effectively manage, automate, and send multimedia messages, such as images, videos, and documents to WhatsApp Channels in 2024. This guide provides comprehensive instructions for using the WhatsApp API to engage your audience and deliver rich content. Includes ready-to-use code examples for easy integration!
🤩 🤖 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 channels 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
- Have a WhatsApp number already linked to the platform and online.
- Channel WhatsApp ID (WID) that you can find in two ways:
- On your WhatsApp number’s management panel, go to “Groups”. From there you will see the channels your number has access to.
- 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:
Prepare the request
Target API URL
https://api.wassenger.com/v1/messages
Required HTTPS headers
Content-Type: application/json
Token: $API-TOKEN
Request body in JSON format for an image message
{
"channel": "$channel_ID@newsletter",
"message": "This is a caption for an image message",
"media": {
"url": "https://picsum.photos/seed/picsum/600/400",
"viewOnce": false
}
}
Request body in JSON format for a video message
{
"channel": "$channel_ID@newsletter",
"message": "This is a caption for an image message",
"media": {
"url": "https://download.samplelib.com/mp4/sample-5s.mp4",
"viewOnce": false
}
}
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
Explore how to use the code in your browser without installing any software.
Send images to a WhatsApp Channel
# 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 = {
"channel": "$channel_ID@newsletter",
"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([
'channel' => '$channel_ID@newsletter',
'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([
'channel' => '$channel_ID@newsletter',
'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("{\"channel\":\"$channel_ID@newsletter\", \"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))
}
// 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", "{\"channel\":\"$channel_ID@newsletter\", \"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 = "{\"channel\":\"$channel_ID@newsletter\",\"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("{\"channel\":\"$channel_ID@newsletter\", \"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 API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!
Send videos to a WhatsApp Channel
# 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 = {
"channel": "$channel_ID@newsletter",
"message": "This is a caption for an image message",
"media": {
"url": "https://download.samplelib.com/mp4/sample-5s.mp4",
"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([
'channel' => '$channel_ID@newsletter',
'message' => 'This is a caption for an image message',
'media' => [
'url' => 'https://download.samplelib.com/mp4/sample-5s.mp4',
'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([
'channel' => '$channel_ID@newsletter',
'message' => 'This is a caption for a video message',
'media' => [
'url' => 'https://download.samplelib.com/mp4/sample-5s.mp4',
'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("{\"channel\":\"$channel_ID@newsletter\", \"message\":\"This is a caption for a video message\", \"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\", \"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))
}
// 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", "{\"channel\":\"$channel_ID@newsletter\", \"message\":\"This is a caption for a video message\", \"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\", \"viewOnce\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
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 = "{\"channel\":\"$channel_ID@newsletter\",\"message\":\"This is a caption for a video message\",\"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\\",\\"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("{\"channel\":\"$channel_ID@newsletter\", \"message\":\"This is a caption for a video message\", \"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\", \"viewOnce\":false}}")
.asString();
🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!
Live API testing
You can live-test and play with the API directly from your browser.
Once you are done testing, get the auto-generated code example in your preferred programming language and you will be ready to go.
🤩 🤖 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**!**
FAQ
Can I use Wassenger to send marketing messages?
As you may know, WhatsApp has strict policies about sending unsolicited marketing messages, illicit content or spam.
Sending marketing or any unsolicited messages to users is not allowed and you would put your WhatsApp number at a high risk of getting banned.
WhatsApp communication is unsuitable for all business cases, so we recommend designing a legitimate and user-approved communication strategy to avoid problems.
Please read our guidelines with communication best practices and how to prevent getting banned.
How to send messages to multiple phone numbers 📲
You have to send numerous API requests, one per target phone number.
For instance, 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:
https://app.wassenger.com/docs/#tag/Messages/operation/createMessage







