Media
Uploading a file
Section titled “Uploading a file”POST /messages/whatsapp/media — scope WHATSAPP_SEND, multipart/form-data. Hands the
bytes to Meta and answers with the id they can be sent by.
curl -X POST "https://vaarto.com/api/v1/messages/whatsapp/media" \ -H "Authorization: Bearer $VAARTO_API_KEY" \ -F "from=+919812345678"const form = new FormData();form.set("file", new Blob([pdfBytes], { type: "application/pdf" }), "invoice-1029.pdf");form.set("from", "+919812345678");
const res = await fetch("https://vaarto.com/api/v1/messages/whatsapp/media", { method: "POST", headers: { Authorization: `Bearer ${process.env.VAARTO_API_KEY}` }, body: form,});
const { data } = await res.json();import os, requests
res = requests.post( "https://vaarto.com/api/v1/messages/whatsapp/media", headers={"Authorization": f"Bearer {os.environ['VAARTO_API_KEY']}"}, files={"file": ("invoice-1029.pdf", open("invoice-1029.pdf", "rb"), "application/pdf")}, data={"from": "+919812345678"}, timeout=60,)
data = res.json()["data"]$data = Http::withToken(env('VAARTO_API_KEY')) ->attach('file', file_get_contents('invoice-1029.pdf'), 'invoice-1029.pdf') ->post('https://vaarto.com/api/v1/messages/whatsapp/media', [ 'from' => '+919812345678', ]) ->json('data');{ "data": { "id": "1024873...", "mimeType": "application/pdf", "filename": "invoice-1029.pdf", "expiresInDays": 30 } }| Field | Notes |
|---|---|
file |
the bytes. One file per request |
from |
which of your numbers uploads it. Defaults to your default number |
What WhatsApp accepts
Section titled “What WhatsApp accepts”| Kind | Accepted | Limit |
|---|---|---|
| Image | JPEG, PNG | 5 MB |
| Video | MP4, 3GP | 16 MB |
| Audio | AAC, MP4, MPEG, AMR, OGG, Opus | 16 MB |
| Document | PDF, TXT, Word, Excel, PowerPoint | 100 MB |
Anything outside the list is refused here rather than at Meta, as
400 UNSUPPORTED_MEDIA_TYPE; over the limit is 400 MEDIA_TOO_LARGE. The kind
is read from the file’s own content type, so send one that is right — a PDF
announced as application/octet-stream is not a document to Meta.
Reach for this rather than link when the file is yours to produce. A link is a
public HTTPS URL that Meta fetches, which means hosting the invoice somewhere reachable,
keeping it reachable until Meta has taken its copy, and deciding when it is safe to take
down. An id has none of that — the bytes are already with Meta before you send.
Meta scopes media to the number that uploaded it, so an id taken on one of your numbers cannot be sent from another. It is good for 30 days and may be sent as many times as you like in that window: one upload serves the same PDF going to a thousand recipients.
Sending
Section titled “Sending”Media is a third kind of send, alongside text and template, and follows the same
window rule as text — there is no media template to fall back on.
curl -X POST "https://vaarto.com/api/v1/messages/whatsapp" \ -H "Authorization: Bearer $VAARTO_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": "+919876543210", "media": { "type": "image", "link": "https://yourcdn.com/invoice-1029.png", "caption": "Your invoice" } }'const res = await fetch("https://vaarto.com/api/v1/messages/whatsapp", { method: "POST", headers: { Authorization: `Bearer ${process.env.VAARTO_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ to: "+919876543210", media: { type: "image", link: "https://yourcdn.com/invoice-1029.png", caption: "Your invoice", }, }),});
const { data } = await res.json();import os, requests
res = requests.post( "https://vaarto.com/api/v1/messages/whatsapp", headers={"Authorization": f"Bearer {os.environ['VAARTO_API_KEY']}"}, json={ "to": "+919876543210", "media": { "type": "image", "link": "https://yourcdn.com/invoice-1029.png", "caption": "Your invoice", }, }, timeout=10,)
data = res.json()["data"]$data = Http::withToken(env('VAARTO_API_KEY')) ->post('https://vaarto.com/api/v1/messages/whatsapp', [ 'to' => '+919876543210', 'media' => [ 'type' => 'image', 'link' => 'https://yourcdn.com/invoice-1029.png', 'caption' => 'Your invoice', ], ]) ->json('data');| Field | Notes |
|---|---|
type |
image, video, audio, document or sticker |
link |
a public HTTPS URL. Meta fetches it — the bytes never pass through this API |
id |
media already uploaded to Meta. Give link or id, never both |
caption |
shown under the attachment. Not accepted on audio or sticker |
filename |
what the recipient’s phone saves it as. Documents only |
Attaching a file to a template
Section titled “Attaching a file to a template”A media send is free-form, so it only reaches somebody inside the
24-hour window. To put a file in front of a customer outside it, the
file has to ride in the header of an approved template — a billing template whose header
Meta approved as DOCUMENT, carrying the invoice as that document.
That is template.headerMedia:
curl -X POST "https://vaarto.com/api/v1/messages/whatsapp" \ -H "Authorization: Bearer $VAARTO_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": "+919876543210", "template": { "name": "invoice_ready", "language": "en", "variables": { "name": "Asha", "amount": "₹4,200" }, "headerMedia": { "id": "1024873...", "filename": "invoice-1029.pdf" } } }'const res = await fetch("https://vaarto.com/api/v1/messages/whatsapp", { method: "POST", headers: { Authorization: `Bearer ${process.env.VAARTO_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ to: "+919876543210", template: { name: "invoice_ready", language: "en", variables: { name: "Asha", amount: "₹4,200" }, headerMedia: { id: mediaId, filename: "invoice-1029.pdf" }, }, }),});res = requests.post( "https://vaarto.com/api/v1/messages/whatsapp", headers={"Authorization": f"Bearer {os.environ['VAARTO_API_KEY']}"}, json={ "to": "+919876543210", "template": { "name": "invoice_ready", "language": "en", "variables": {"name": "Asha", "amount": "₹4,200"}, "headerMedia": {"id": media_id, "filename": "invoice-1029.pdf"}, }, }, timeout=10,)$data = Http::withToken(env('VAARTO_API_KEY')) ->post('https://vaarto.com/api/v1/messages/whatsapp', [ 'to' => '+919876543210', 'template' => [ 'name' => 'invoice_ready', 'language' => 'en', 'variables' => ['name' => 'Asha', 'amount' => '₹4,200'], 'headerMedia' => ['id' => $mediaId, 'filename' => 'invoice-1029.pdf'], ], ]) ->json('data');| Field | Notes |
|---|---|
id |
from uploading a file. Nothing of yours has to be reachable |
link |
a public HTTPS URL instead. Give id or link, never both |
filename |
what the recipient’s phone saves it as. Documents only |
Whether a template takes one was decided by Meta when it approved the template, not here:
| Template header | headerMedia |
Result |
|---|---|---|
DOCUMENT, IMAGE or VIDEO |
given | sent |
DOCUMENT, IMAGE or VIDEO |
missing | 400 MISSING_HEADER_MEDIA |
| text, or no header | given | 400 UNEXPECTED_HEADER_MEDIA |
GET /templates reports each template’s header, so you can tell which
of your templates needs a file before you send one.
If you do use link here, the same rule applies as everywhere else Meta fetches a URL: it
must still answer when Meta takes its copy, which is not necessarily the moment your send
returns. Do not take it down on the response arriving — that is the mistake id exists to
avoid.
Reading one back
Section titled “Reading one back”An inbound attachment arrives as a media id, not a URL, and the URL Meta exchanges it for expires in minutes and needs the account’s token. So the bytes are streamed through this API instead:
curl -L "https://vaarto.com/api/v1/messages/whatsapp/MESSAGE_ID/media" \ -H "Authorization: Bearer $VAARTO_API_KEY" -o attachment.binconst res = await fetch("https://vaarto.com/api/v1/messages/whatsapp/MESSAGE_ID/media", { headers: { Authorization: `Bearer ${process.env.VAARTO_API_KEY}` },});
const bytes = Buffer.from(await res.arrayBuffer());import os, requests
res = requests.get( "https://vaarto.com/api/v1/messages/whatsapp/MESSAGE_ID/media", headers={"Authorization": f"Bearer {os.environ['VAARTO_API_KEY']}"}, timeout=10,)
open("attachment.bin", "wb").write(res.content)$response = Http::withToken(env('VAARTO_API_KEY')) ->get('https://vaarto.com/api/v1/messages/whatsapp/MESSAGE_ID/media');
file_put_contents('attachment.bin', $response->body());Scope MEDIA_READ, not MESSAGES_READ — the log is text and status, this is the file
itself.
It is also the one endpoint that does not answer in the { data } envelope: the response
is the file, with content-type from Meta and a content-disposition filename for
documents. GET /messages/whatsapp/:id tells you in advance whether there is anything to
fetch, as hasMedia.
Attachments do not expire here. Meta keeps media for about 30 days and then stops serving it, so every attachment is copied into our own storage shortly after it arrives and this endpoint reads it back from there. A thread from last year opens its files exactly like a thread from this morning.
A 410 is therefore now rare, and means the attachment predates archiving or was already gone at Meta before it could be copied.
This covers attachments you sent as a link too. Meta fetches that URL itself, so
nothing passed through this API at the time — the link is archived separately, and
once it is, the attachment reads back like any other. Until then hasMedia is
false and this endpoint answers 409 MEDIA_NOT_ARCHIVED. The URL must still be
reachable when the copy is taken, so do not take it down the moment Meta has
fetched it.
| Failure | HTTP | Code |
|---|---|---|
| Never archived, and Meta’s 30 days have run out | 410 | MEDIA_EXPIRED |
| Not yet archived and Meta would not serve it | 410 | MEDIA_UNAVAILABLE |
Sent as a link and not archived yet |
409 | MEDIA_NOT_ARCHIVED |
| Meta could not be reached, or refused | 502 | MEDIA_UNAVAILABLE |