Skip to content

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 https://api.greenapi.com/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}

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#

File from message

DownloadFile errors#

For a list of errors common to all methods, refer to Common errors section

Примеры кода#

import requests
import json

url = "{{host}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}"

payload = json.dumps({
  "chatId": "790000312312@c.us",
  "idMessage": "A322F800D3F12CD4858CC947DAFB77A2"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
curl --location -g --request POST '{{host}}/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("https://api.greenapi.com")
    .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("https://api.greenapi.com")
    .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);