mediaUrl- A presigned URL that expires after 1 hourmediaId- A permanent identifier for fetching fresh URLs via the Media API
Webhook Payload
Message webhooks include both fields for media content:Webhook Payload
Immediate vs. Long-term Access
Use mediaUrl for Immediate Access
The mediaUrl is a presigned URL valid for 1 hour from when the webhook is sent. Use it when you need to:
- Download the file immediately when receiving the webhook
- Display the media in real-time notifications
- Process the file right away (e.g., image analysis, transcription)
Use mediaId for Long-term Access
The mediaId is a permanent identifier that you can use to fetch fresh presigned URLs at any time (until the media expires based on your organization’s retention settings). Use it when you need to:
- Store a reference to retrieve the file later
- Build a media gallery or message history
- Access the file after the initial URL expires
Fetching Media with the API
To get a fresh presigned URL for stored media, use the Media API:Get Media by ID
Media Response
Media Retention
Media files are stored according to your organization’smediaRetentionDays setting (default: 90 days). After this period:
- The media file is permanently deleted from storage
- Requests for the
mediaIdwill return a404 Not Foundresponse - You should handle this case in your application
You can configure your media retention period in the organization settings.
Best Practices
Store the mediaId, not the mediaUrl
Store the mediaId, not the mediaUrl
Since presigned URLs expire after 1 hour, always store the
mediaId in your database. You can fetch a fresh URL whenever you need to display or download the file.Download immediately if you need the original file
Download immediately if you need the original file
If you need to keep a permanent copy of the media file (e.g., for compliance, backup, or offline access), download it immediately when you receive the webhook using the
mediaUrl.Handle expired media gracefully
Handle expired media gracefully
After your organization’s retention period, media requests return
404 Not Found. Your application should handle this case by showing a placeholder or message indicating the media is no longer available.Use app keys for media access
Use app keys for media access
Media is scoped to your application. Use your app API key (
sk_live_app_* or sk_test_app_*) to access media - each app can only access its own media files.Supported Platforms
| Platform | Media Types | Notes |
|---|---|---|
| SMS/MMS | Images, videos, audio | MMS media is downloaded and stored when received |
| Images, videos, audio, documents, stickers | All media types except contacts and location |
Related
- Webhooks - Configure webhooks for your application
- Media API - Full API reference for media operations
- Receiving SMS/MMS - Handle incoming SMS and MMS messages
- Receiving WhatsApp - Handle incoming WhatsApp messages