Updated on November 10, 2026
A media ID created by uploading a file to the WhatsApp Cloud API is valid for 30 days, a media ID that arrives in the webhook for received media is valid for 7 days, and the download URL returned by GET /{media-id} expires after 5 minutes. While it is valid, the same media ID can be used in as many sends as you like, so you don’t have to upload the same file again for every recipient. Once it expires, the fix is a new upload and swapping the stored ID.
This article covers the media ID lifecycle: the official expiration times, the difference between id, link and the template header handle, a media ID cache with automatic renewal, and when to delete media early. If you haven’t sent any media yet, start with how to send media with the WhatsApp API. For files your customers send you, see how to download media from the webhook.
The official expiration times in one table
Every time limit below is written in Meta’s documentation. The Media page covers the first three; the Send messages page covers link caching.
| What | Time limit | What happens next |
|---|---|---|
Media ID returned by POST /{phone-number-id}/media | 30 days (the file is stored encrypted unless you delete it sooner) | The ID expires; sends that use it fail |
| Media ID received in a media message webhook | 7 days to download | The file can no longer be downloaded |
URL returned by GET /{media-id} (the url field) | 5 minutes | Query the media ID again to get a new URL |
File sent by link | Cached by the Cloud API for 10 minutes | A new send with the same link fetches the file from your server again |
Two things the documentation does not state, so don’t assume them: there is no published lifetime for the Resumable Upload header handle, and there is no sign that a media ID can be renewed or extended. To get another 30 days, upload again.
Media ID, link and header handle are not the same thing
The most common mix-up in new integrations is treating these three identifiers as interchangeable. They serve different moments:
Media ID (id) | Link (link) | Header handle (header_handle) | |
|---|---|---|---|
| How you get it | POST /{phone-number-id}/media | Public HTTPS URL on your server or CDN | Resumable Upload API: POST /{app-id}/uploads, then POST /upload:{session-id} |
| Typical format | A number, like 1037543291543636 | https://cdn.example.com/file.pdf | Prefixed string, like 4::aW... |
| Where it’s used | Sending media messages and media-header templates | Sending media messages and media-header templates | Only in the header example field when creating a template |
| Documented lifetime | 30 days | 10-minute internal cache | Not published |
| Meta’s guidance | Recommended | “Not recommended” for performance | Required to create a media-header template |
The point that trips people up: the header handle lets Meta review the template with a sample file. It is not the file you send. When you actually send the template, the header takes an uploaded id or a link, just like any media message. The full sending walkthrough is in how to send a template with the WhatsApp API.
Want to try it while you read? Create a Vectalk account and send your first message through the official API. Create free account →
One upload, many recipients
If the same file goes to a lot of people (this month’s catalog, a welcome video, a terms PDF), upload it once and reuse the ID. The upload is a multipart/form-data request with file, type and messaging_product:
curl -X POST "https://graph.facebook.com/v27.0/$PHONE_NUMBER_ID/media" \
-H "Authorization: Bearer $WHATSAPP_TOKEN" \
-F "messaging_product=whatsapp" \
-F "file=@catalog-november.pdf;type=application/pdf"
The response contains only the ID:
{ "id": "1037543291543636" }
Then the same id goes into every send. Here is a Node.js 18+ example using native fetch:
const GRAPH = 'https://graph.facebook.com/v27.0';
const PHONE_ID = process.env.PHONE_NUMBER_ID;
const TOKEN = process.env.WHATSAPP_TOKEN;
async function sendDocument(to, mediaId) {
const r = await fetch(`${GRAPH}/${PHONE_ID}/messages`, {
method: 'POST',
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
messaging_product: 'whatsapp',
to,
type: 'document',
document: { id: mediaId, filename: 'catalog-november.pdf' },
}),
});
const body = await r.json();
if (!r.ok) throw Object.assign(new Error('send failed'), { apiError: body.error });
return body.messages[0].id; // wamid
}
const mediaId = '1037543291543636';
for (const number of ['5511988887777', '5521977776666']) {
console.log(number, await sendDocument(number, mediaId));
}
Remember that a free-form media message can only be sent while the 24-hour customer service window is open. Outside it, the file goes in the header of an approved template, and reusing the ID works the same way: the same id goes into components[].parameters[].document.id (or image.id, video.id) for each send. Sending to many numbers in a row needs pacing and error handling on your side; a 200 response only confirms Meta accepted the request, and delivery is reported later by the status webhook.
A media ID cache with automatic renewal
Keeping the ID in a .env file works until day 31. In production, treat the media ID as a resource with an expiration date: record when it was created and create a new one before it lapses. The minimum table looks like this:
| Field | Purpose |
|---|---|
phone_number_id | The number the upload was made from |
File sha256 | Identifies the content; a changed file gets a new hash and therefore a new upload |
media_id | The ID returned by Meta |
uploaded_at | Upload date and time |
Why the key includes the number: the documentation says that if you pass phone_number_id to GET or DELETE /{media-id}, the request is only processed when that number matches the one the media was uploaded on. The media is tied to the number it was uploaded on. If your application serves several numbers, upload once per number and don’t share IDs between them.
A Node.js example that continues the previous one (same constants and the sendDocument function), with a Map standing in for your database. The renewal margin (25 days here) is our own choice to stay clear of the 30-day limit; adjust it to your operation:
import { readFile } from 'node:fs/promises';
import crypto from 'node:crypto';
const RENEW_AFTER_MS = 25 * 24 * 60 * 60 * 1000; // margin before 30 days
const cache = new Map(); // replace with a table in your database
async function upload(buffer, mime, name) {
const form = new FormData();
form.append('messaging_product', 'whatsapp');
form.append('type', mime);
form.append('file', new Blob([buffer], { type: mime }), name);
const r = await fetch(`${GRAPH}/${PHONE_ID}/media`, {
method: 'POST',
headers: { Authorization: `Bearer ${TOKEN}` },
body: form,
});
const body = await r.json();
if (!r.ok) throw new Error(JSON.stringify(body.error));
return body.id;
}
export async function getMediaId(path, mime, { force = false } = {}) {
const buffer = await readFile(path);
const hash = crypto.createHash('sha256').update(buffer).digest('hex');
const key = `${PHONE_ID}:${hash}`;
const current = cache.get(key);
const fresh = current && Date.now() - current.uploadedAt < RENEW_AFTER_MS;
if (fresh && !force) return current.mediaId;
const mediaId = await upload(buffer, mime, path.split('/').pop());
cache.set(key, { mediaId, uploadedAt: Date.now() });
return mediaId;
}
And a safety net for when the ID fails even inside the margin (deleted by mistake, lost cache, wrong clock): if the send errors, upload once more and retry.
export async function sendWithRenewal(to, path, mime) {
let mediaId = await getMediaId(path, mime);
try {
return await sendDocument(to, mediaId);
} catch (e) {
console.warn('send with media ID failed, uploading again', e.apiError);
mediaId = await getMediaId(path, mime, { force: true });
return sendDocument(to, mediaId);
}
}
The image messages page says a request fails if the media ID is invalid or has expired, and that the API then returns an error response instead of a message ID. It doesn’t pin down a specific error code for “expired ID”, so log the code and error_data.details you get and don’t rely on a single number. To avoid pointless re-uploads, limit the retry to media-related errors, not failures like an invalid number or a missing template. Template header formatting errors are covered in template parameter errors.
When to use link, and the 10-minute cache
link has its place: files already on a public CDN, one-off sends, or files generated on the fly, such as a boleto (a bank payment slip widely used in Brazil) behind a signed URL. The trade-off is that Meta has to download the file from your server at send time, and the URL must be on a publicly accessible server or the send fails.
The detail few people know is in the sending docs: with link, the Cloud API caches the file for 10 minutes, and later sends with exactly the same link reuse the cached file. That helps when you send the same file to many people in a row, but it bites when the file changes and the URL stays the same. Example: you replace offer.jpg on your CDN and send again five minutes later. Meta may deliver the old image.
The official workaround is to append a random query string to the link. The Cloud API treats it as a new asset, fetches it from your server again and caches it for another 10 minutes:
function cacheBustedLink(url, version) {
const u = new URL(url);
u.searchParams.set('v', version); // e.g. file hash or last-modified date
return u.toString();
}
// https://cdn.example.com/offer.jpg?v=9f2c1a
Using the file hash as the version beats a random number: the link only changes when the content changes, so the cache keeps working in your favor during back-to-back sends.
Received media: the webhook ID is for downloading, not storing
When a customer sends a photo or a PDF, the webhook carries a media ID that can be downloaded for 7 days. The download URL, obtained with GET /{media-id} (or from the webhook’s own url field), lasts 5 minutes. Storing either one in your database as a permanent reference is a bug scheduled for next week.
The right flow is to download right away, save the file to your own storage and store the path to your copy. If you need to forward that file to someone else (a receipt passed on to your finance team, say), upload it again from your copy. The documentation doesn’t say a received media ID can be used to send, and a fresh upload gives you the full 30 days. Download code with retries and hash checks is in download media from the webhook.
If the GET on the URL returns 404 Not Found, Meta’s guidance is to get a new URL by querying the media ID and try again; if that doesn’t work, refresh your access token.
Deleting media before the 30 days
Uploaded media is stored for 30 days unless you delete it sooner. To delete it, use DELETE /{media-id}:
curl -X DELETE \
"https://graph.facebook.com/v27.0/$MEDIA_ID?phone_number_id=$PHONE_NUMBER_ID" \
-H "Authorization: Bearer $WHATSAPP_TOKEN"
Response:
{ "success": true }
phone_number_id is optional; with it, Meta only deletes the media if it was uploaded on that number, which prevents deleting another number’s media by accident in multi-number systems.
Deleting makes sense when the file contains personal data and was meant for a single send: an invoice copy, a signed contract, a lab report, a receipt. Data protection laws such as Brazil’s LGPD (Law 13,709/2018) or the GDPR ask you not to keep personal data longer than necessary. This is context, not legal advice: set your retention policy with your lawyer. After deleting, remove the ID from your cache so no send tries to use it.
Header handle: the template upload
To create a template with an image, video or document header, Meta requires a sample file uploaded through the Resumable Upload API. It takes two calls. The first opens an upload session on your app ID:
curl -X POST "https://graph.facebook.com/v27.0/$APP_ID/uploads?file_name=sample.jpg&file_length=48213&file_type=image/jpeg&access_token=$TOKEN"
It returns { "id": "upload:<SESSION_ID>" }. The second sends the file with file_offset: 0:
curl -X POST "https://graph.facebook.com/v27.0/upload:$SESSION_ID" \
-H "Authorization: OAuth $TOKEN" \
-H "file_offset: 0" \
--data-binary @sample.jpg
The response returns the handle in the h field, which goes into example.header_handle of the HEADER component when you create the template. If the upload is interrupted, GET /upload:{session-id} returns the file_offset so you can resume where it stopped. This API accepts PDF, JPEG, PNG and MP4.
Three things not to mix up:
- The handle does not replace the media ID when sending. At send time, the header uses
idorlink. - The handle comes from
/{app-id}/uploads, tied to the app; the media ID comes from/{phone-number-id}/media, tied to the number. - Meta doesn’t publish a lifetime for the handle. Since it’s only used when creating the template, there’s no reason to store it.
Common media ID mistakes
- Storing the download URL instead of the ID. The URL expires in 5 minutes. Store the ID (for uploads) or the path in your storage (for received media).
- Hard-coding the ID. It works in testing and breaks 30 days later. Use a cache with the upload date.
- Sharing IDs across numbers. The media is tied to the number it was uploaded on. Upload once per number.
- Using the header handle to send. It’s only for template creation.
- Changing the file but keeping the link. With the 10-minute cache, the recipient may get the old version. Version the URL.
- Wrong MIME type on upload. If the declared type doesn’t match the content, the send can fail with error 131053. Check the limits: images up to 5 MB, audio and video up to 16 MB, documents up to 100 MB, stickers up to 100 KB (static) or 500 KB (animated).
Media IDs with Vectalk
Vectalk is a proxy for the official WhatsApp Business API, so media IDs follow the same rules as Meta’s. The media routes, documented at docs.vectalk.com.br, are:
POST https://apis.vectalk.com.br/api/mediato upload (fieldsfile,typeandmessaging_product), which returns{ "id": "..." }.GET https://apis.vectalk.com.br/api/media/{mediaId}to get the temporary download URL.GET https://apis.vectalk.com.br/api/media/{mediaId}/downloadto download the binary directly.DELETE https://apis.vectalk.com.br/api/media/{mediaId}to delete the media from Meta’s servers.
Media routes require an instance token, created in the dashboard under Settings, API Tokens; with it, the phone_number_id is resolved automatically and the ID is naturally tied to that number. The returned id goes into a send via POST https://apis.vectalk.com.br/api/messages, with the same body Meta uses. The ID cache and renewal logic live in your own system. Create an account at apps.vectalk.com.br/register to try it.
Frequently asked questions
How long is a WhatsApp media ID valid?
A media ID returned by an upload is valid for 30 days. A media ID received in a media webhook can be downloaded for 7 days. The download URL from GET /{media-id} expires after 5 minutes.
Can I use the same media ID for multiple recipients?
Yes. Within the 30 days, the same id can be used in as many sends as you want, in media messages or in template headers. It’s the approach Meta recommends so each send doesn’t depend on your server.
Can I renew a media ID without uploading again?
The documentation has no endpoint to extend its lifetime. To get another 30 days, upload the file again and replace the ID in your cache.
What’s the difference between a media ID and a header handle?
The media ID comes from the number’s /media endpoint and is used for sending. The header handle comes from the app’s Resumable Upload API and is only used as a sample when creating a media-header template.
What happens if I send an expired media ID?
The request fails and the API returns an error response instead of a message ID. Handle it by uploading once more and resending. For other payload errors, such as a missing or invalid parameter, the fix is to correct the request body.
Official sources consulted on November 10, 2026: Media (Cloud API), Send messages: media caching, Image messages, Template media, Resumable Upload API, Cloud API error codes, Vectalk docs: Media Upload, Vectalk docs: Authentication.
Try the official WhatsApp API today
Create your account, generate a token and send your first message with the quick-start guide. Same payloads and webhooks as Meta's Cloud API.
