How to retrieve files
How developers can retrieve any type of file (document, image, audio, video, etc.) from WhatsApp messages using Whapi.Cloud's API
If your system receives messages from users and you need to download the source files for internal processing, storage, or forwarding, you will find it useful to learn about two different ways to achieve this goal.
Whapi.Cloud provides programmatic access to media files received in WhatsApp chats or groups, regardless of whether the file is a PDF, image, audio recording, or video. You can either download the file directly via the API or set up automatic cloud storage using download links.
Method 1: Get the File by Media ID Using the Get Media Endpoint
When your webhook receives an incoming message that includes a file, you'll see a field such as document.id
, image.id
, or video.id
. This is the Media ID
โ a unique identifier of the file stored temporarily on the WhatsApp server.
Webhook Example (Message with PDF document)
Step-by-step instructions to obtain this file:
1) Capture the webhook from an incoming message or receive a message via an HTTP call;
2) Extract the Media ID
from the corresponding media object;
3) Make the GET Media request to the following endpoint: GET /media/{media-id}
Example:
Important Notes: The response body contains the actual file, not just a URL!
Method 2: Enable Auto Download and Use the File URL
Whapi.Cloud provides an optional setting that enables automatic uploading of incoming media to secure cloud storage. With this setting active, each incoming file includes a direct public link.
How to Enable It:
Go to your channel settings;
Enable the toggle: "Auto Download";
What Happens Next:
How it works?
Enabling the setting will add the Link parameter to the JSON array, where you will immediately receive a direct link to the file:
The link to the media files processed by your number at the time of the enabled setting is bound to the message, which means that you will be able to get a link to the media file via API Call.
Conclusion
Whapi.Cloud offers two powerful methods to retrieve files from WhatsApp:
Use the Get Media endpoint when you want to control file retrieval manually.
Enable Auto Download for easier, automated access with public links.
Last updated
Was this helpful?