Skip to content

Media

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.

Terminal window
curl -X POST "https://vaarto.com/api/v1/messages/whatsapp/media" \
-H "Authorization: Bearer $VAARTO_API_KEY" \
-F "from=+919812345678"
{ "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
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.

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.

Terminal window
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"
}
}'
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

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:

Terminal window
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" }
}
}'
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.

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:

Terminal window
curl -L "https://vaarto.com/api/v1/messages/whatsapp/MESSAGE_ID/media" \
-H "Authorization: Bearer $VAARTO_API_KEY" -o attachment.bin

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