DownloadFile#
The method is aimed for downloading incoming and outgoing files. Links to incoming files are transmitted in Incoming messages, and you can also get them using LastIncomingMessages method. You can get links to outgoing files using LastOutgoingMessages method.
Files storage period and, accordingly, the capability to download them is limited by WhatsApp
Request#
POST
{{apiUrl}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}
For apiUrl
, idInstance
and apiTokenInstance
request parameters, refer to Before you start section.
Request parameters#
Parameter | Type | Mandatory | Description |
---|---|---|---|
chatId | string | Yes | Chat id, for example 7900023125@c.us |
idMessage | string | Yes | Message Id transmitted in Incoming messages or when sending files using SendFileByUrl, SendFileByUpload methods. This parameter is transmitted as the final part of the url request |
Response#
Response parameters#
Parameter | Type | Description |
---|---|---|
downloadUrl | string | Link to the file from message |
Response body example#
{
"downloadUrl": "https://sw-media.storage.yandexcloud.net/1103912412/a6679d42-2f7f-4121-acfe-1f993dfcf123.png"
}
DownloadFile errors#
For a list of errors common to all methods, refer to Common errors section
HTTP code | Error identifier | Description |
---|---|---|
400 | Bad Request Validation failed | Validation error |
400 | Validation failed. Details: 'value' must have at least 2 keys | Validation failed. Details: value must have at least 2 keys |
400 | File message encrypted url not found by chatId 790000312312@c.us and idMessage A322F800D3F12CD4858CC947DAFB77A2 | File missing in the message |
500 | Internal error when downloading file by chatId 790000312312@c.us and idMessage A322F800D3F12CD4858CC947DAFB77A2 | The file is not available on WhatsApp servers, download via API is not possible |
Request examples#
import requests
import json
url = "{{apiUrl}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}"
payload = json.dumps({
"chatId": "790000312312@c.us",
"idMessage": "A322F800D3F12CD4858CC947DAFB77A2"
})
headers = {
'Content-Type': 'application/json'
}
response = requests.post(url, json=payload)
print(response.text)
curl --location -g --request POST '{{apiUrl}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"chatId": "79000001234@c.us",
"idMessage": "A322F800D3F12CD4858CC947DAFB77A2"
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/downloadFile/")
.append({{apiTokenInstance}});
var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
var jsonBody = "{\"chatId\": \"79000001234@c.us\",\"idMessage\": \"A322F800D3F12CD4858CC947DAFB77A2\"}";
var requestEntity = new HttpEntity<>(jsonBody, headers);
var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.POST, requestEntity, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/downloadFile/")
.append({{apiTokenInstance}});
var response = Unirest.post(requestUrl.toString())
.header("Content-Type", "application/json")
.body("{\"chatId\": \"79000001234@c.us\",\"idMessage\": \"A322F800D3F12CD4858CC947DAFB77A2\"}")
.asString();
System.out.println(response);
Sub DownloadFile()
Dim url As String
Dim RequestBody As String
Dim http As Object
Dim response As String
' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
url = "{{apiUrl}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}"
' chatId - personal or group chat identifier whose message history you want to receive, count - number of messages to receive, default value 100
RequestBody = "{""chatId"":""71234567890@c.us"",""idMessage"":""E5A2563784F535FD43B3B83142E1234E""}"
Set http = CreateObject("MSXML2.XMLHTTP")
With http
.Open "POST", url, False
.setRequestHeader "Content-Type", "application/json"
.send RequestBody
End With
response = http.responseText
Debug.Print response
' Outputting the answer to the desired cell
Range("A1").Value = response
Set http = Nothing
End Sub