SendFileByUrl#
The method is aimed for sending a file uploaded by Url. The message will be added to the send queue. The message will be kept for 24 hours in the queue and will be sent immediately after phone authorization. The rate at which messages are sent from the queue is managed by Message sending delay parameter.
The minimum interval for sending messages from the queue using the SendFileByUrl method is 5 seconds.
Video, audio and image files available for viewing and listening to are sent as in native-mode WhatsApp. Documents are sent in the same way as in native-mode WhatsApp. Outgoing file type and send method is determined by the file extension. Description is only added to images and video.
The maximum size of outgoing files is 100 MB.
Request#
To send a file, you have to execute a request at:
POST https://api.greenapi.com/waInstance{{idInstance}}/sendFileByUrl/{{apiTokenInstance}}
For idInstance
and apiTokenInstance
request parameters, refer to Before you start section.
Request parameters#
Parameter | Type | Mandatory | Description |
---|---|---|---|
chatId | string | Yes | Chat Id |
urlFile | string | Yes | Link to outgoing file |
fileName | string | Yes | File name. Must contain the file extension |
caption | string | No | File caption. Caption added to video, images. |
quotedMessageId | string | No | Quoted message ID. If present, the message will be sent quoting the specified chat message |
Request body example#
Sending a message to a personal chat:
{
"chatId": "11001234567@c.us",
"urlFile": "https://my.site.com/img/horse.png",
"fileName": "horse.png",
"caption": "Little horse"
}
Sending a message to a group chat:
{
"chatId": "11001234567-1581234048@g.us",
"urlFile": "https://my.site.com/img/horse.png",
"fileName": "horse.png",
"caption": "Little horse"
}
Sending a quoted message:
{
"chatId": "11001234567@с.us",
"urlFile": "https://my.site.com/img/horse.png",
"fileName": "horse.png",
"caption": "Little horse",
"quotedMessageId": "361B0E63F2FDF95903B6A9C9A102F34B"
}
Link format recommendations
-
Symbols a-z, A-Z, 0-9, - (hyphen), _ (gentle underscore) can be used in the link
-
The link must not contain special characters ~$€%#£?! and spaces
-
UTF-8 link character encoding without BOM
-
It is required to transfer non-encoded links (the system encodes the link itself)
-
It is required that the link points to a specific file, and not to the html page link examples
-
Required to use fast storage, no limit on the number of file requests
Response#
Response parameters#
Parameter | Type | Description |
---|---|---|
idMessage | string | Outgoing message Id |
Response body example#
{
"idMessage": "3EB0C767D097B7C7C030"
}
SendFileByUrl errors#
For a list of errors common to all methods, refer to Common errors section
Request examples#
import requests
url = "https://api.greenapi.com/waInstance{{idInstance}}/sendFileByUrl/{{apiTokenInstance}}"
payload = "{\r\n \t\"chatId\": \"11001234567@c.us\",\r\n\t\"urlFile\": \"https://avatars.mds.yandex.net/get-pdb/477388/77f64197-87d2-42cf-9305-14f49c65f1da/s375\",\r\n\t\"fileName\": \"horse.png\",\r\n\t\"caption\": \"little horse\"\r\n}"
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
curl --location 'https://api.green-api.com/waInstance{{idInstance}}/sendFileByUrl/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"chatId": "12345678910@c.us",
"urlFile": "https://avatars.mds.yandex.net/get-pdb/477388/77f64197-87d2-42cf-9305-14f49c65f1da/s375",
"fileName": "horse.png",
"caption": "лошадка"
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
.append("https://api.greenapi.com")
.append("/waInstance").append({{idInstance}})
.append("/sendFileByUrl/")
.append({{apiTokenInstance}});
var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
var jsonBody = "{\r\n \t\"chatId\": \"11001234567@c.us\",\r\n\t\"urlFile\": \"https://avatars.mds.yandex.net/get-pdb/477388/77f64197-87d2-42cf-9305-14f49c65f1da/s375\",\r\n\t\"fileName\": \"horse.png\",\r\n\t\"caption\": \"little horse\"\r\n}";
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("/sendFileByUrl/")
.append({{apiTokenInstance}});
var response = Unirest.post(requestUrl.toString())
.header("Content-Type", "application/json")
.body("{\r\n \t\"chatId\": \"11001234567@c.us\",\r\n\t\"urlFile\": \"https://avatars.mds.yandex.net/get-pdb/477388/77f64197-87d2-42cf-9305-14f49c65f1da/s375\",\r\n\t\"fileName\": \"horse.png\",\r\n\t\"caption\": \"little horse\"\r\n}")
.asString();
System.out.println(response);
Sub SendFileByUrl()
Dim url As String
Dim RequestBody As String
Dim http As Object
' The idInstance and apiTokenInstance values are available in your account, double brackets must be removed
url = "https://api.greenapi.com/waInstance{{idInstance}}/SendFileByUrl/{{apiTokenInstance}}"
' chatId is the number to send the message (@c.us for private chats, @g.us for group chats), urlFile - url link, fileName - file name with extension, caption - title
RequestBody = "{""chatId"":""90123456789@c.us"",""urlFile"":""https://my.site.com/img/horse.png"",""fileName"":""horse.png"",""caption"":""horse""}"
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