curl --request POST \
--url https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form waba_id=123456789012345 \
--form file='@example-file'import requests
url = "https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "waba_id": "123456789012345" }
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('waba_id', '123456789012345');
form.append('file', '<string>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"waba_id\"\r\n\r\n123456789012345\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"waba_id\"\r\n\r\n123456789012345\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"waba_id\"\r\n\r\n123456789012345\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"waba_id\"\r\n\r\n123456789012345\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "Media uploaded successfully",
"data": {
"handle": "4::aW1hZ2UvanBlZw==:ARYf7QqLNzCm0wd3rKtN6V4hQp9zXxF...",
"media_type": "image"
}
}Upload a media file
Upload an image, video, or document to Meta and receive a temporary media handle for a WhatsApp template header.
Use this endpoint only when you are creating a WhatsApp template with a media HEADER:
- IMAGE header: upload an image with
media_type=image - VIDEO header: upload a video with
media_type=video - DOCUMENT header: upload a document with
media_type=document
Do not use this endpoint for normal message attachments or campaign media uploads. If you want to send a WhatsApp campaign without managing template media handles, use the list/campaign workflow instead: create or import contacts into a list, attach the list to a WhatsApp campaign, upload or select the campaign media there, and send through the campaign.
How to use the returned handle:
- Call
POST /api/v1/whatsapp/templates/upload-mediawith multipart form data:waba_id,media_type, andfile. - Read
data.handlefrom the response. - Call
POST /api/v1/whatsapp/templatesand place that handle atcomponents[i].example.header_handle[0]on the media HEADER component.
Example media HEADER component for the template-create request: set type to HEADER, set format to IMAGE, VIDEO, or DOCUMENT, and set example.header_handle to an array containing the returned handle.
Why this endpoint exists: Meta requires media used in template headers to be uploaded first through a resumable upload session. The template-create request accepts the returned handle, not the binary file.
Handle lifetime: the handle is short-lived. Create the template within about 24 hours after upload. If the handle expires, upload the file again and use the new handle.
Validation before upload:
- image: JPEG or PNG, maximum 5 MB
- video: MP4 or 3GPP, maximum 16 MB
- document: PDF, plain text, Word, Excel, or PowerPoint formats, maximum 100 MB
media_typemust match the file MIME type. For example, uploading a PDF withmedia_type=imagereturns 422.
curl --request POST \
--url https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form waba_id=123456789012345 \
--form file='@example-file'import requests
url = "https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "waba_id": "123456789012345" }
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('waba_id', '123456789012345');
form.append('file', '<string>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"waba_id\"\r\n\r\n123456789012345\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"waba_id\"\r\n\r\n123456789012345\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"waba_id\"\r\n\r\n123456789012345\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://{subdomain}.mihu.ai/api/v1/whatsapp/templates/upload-media")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"waba_id\"\r\n\r\n123456789012345\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "Media uploaded successfully",
"data": {
"handle": "4::aW1hZ2UvanBlZw==:ARYf7QqLNzCm0wd3rKtN6V4hQp9zXxF...",
"media_type": "image"
}
}Authorizations
Use a Bearer token to access these API endpoints. Example: "Bearer {your-token}"
Body
WABA the template will be created under. Must be linked to this tenant (GET /api/v1/whatsapp/wabas to list yours).
"123456789012345"
Determines which header.format the resulting handle is valid for. image→HEADER.format=IMAGE, video→VIDEO, document→DOCUMENT.
image, video, document The actual binary file. Image: jpg/png ≤5MB. Video: mp4/3gp ≤16MB. Document: pdf/txt/doc(x)/xls(x)/ppt(x) ≤100MB.
