DownloadFile#
Beta version
The functionality is in beta. Features may change and may also work unstably.
The method returns the link to a file of a message - an image, a video, a voice message or a sticker.
For a message with a post (sharedMessage) the method does not get a new link: the file is saved by the link from the journal while it is valid.
The method returns a link only to an available file: if Instagram no longer returns the file, the method responds with 404.
There are no permanent links
The file is kept in the storage for 15 days: after that the link stops working. Do not store the link in your database - keep the file itself or request the link again by the same method.
A file larger than 100 MB is not saved to the storage: the method responds with 413.
The method uses the limits on the number of requests per second.
Request#
To get the link to a file, you have to execute a request at:
{{apiUrl}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}
For apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.
Request parameters#
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
chatId | string | Yes | Chat identifier - the numeric identifier of an account or of a group chat, or a username with the @ prefix |
idMessage | string | Yes | The identifier of the message with the attachment |
Request body example#
{
"chatId": "49547665464",
"idMessage": "32992354910263051384774140624896000"
}
Response#
Response parameters#
| Field | Type | Description |
|---|---|---|
downloadUrl | string | The link to the file in the GREEN-API storage |
Response body example#
{
"downloadUrl": "https://storage.yandexcloud.net/sw-media/5100000000/4d506ca7-f348-4452-aace-508f00a2f832.jpg"
}
DownloadFile errors#
For a list of errors common to all methods, refer to the Common errors section
| HTTP code | Error ID | Description |
|---|---|---|
| 400 | Bad Request Validation failed | Validation error |
| 400 | Validation failed. Details: 'idMessage' is required | The message identifier is not passed |
| 400 | Validation failed. Details: 'idMessage' is not allowed to be empty | The message identifier is empty |
| 404 | no media in message 32992354910263051384774140624896000 | There is no such message or there is no attachment in it |
| 404 | media of message 32992354910263051384774140624896000 is no longer available | The file is no longer available on the Instagram side |
| 413 | media of message 32992354910263051384774140624896000 is 157286400 bytes, larger than the 100 MB limit | The file is larger than the allowed size (100 MB by default) - it is not saved to the storage |
| 502 | cannot store media of message 32992354910263051384774140624896000 | The storage has not accepted the file. Repeat the request later |
Request examples#
import requests
url = "{{apiUrl}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}"
payload = {
"chatId": "49547665464",
"idMessage": "32992354910263051384774140624896000"
}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=payload, headers=headers)
print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"chatId": "49547665464",
"idMessage": "32992354910263051384774140624896000"
}'