Skip to content

SendFileByUrl#

Beta version

The functionality is in beta. Features may change and may also work unstably.

The method is used to send an image, a video or a voice message to an Instagram Direct chat by a link.

The message will be added to the send queue. The rate at which messages are sent from the queue is managed by the Message sending delay parameter

The method uses the limits on the number of requests per second.

Files

Instagram Direct supports images, videos and voice messages; document attachments cannot be sent.

A file is sent as a voice message if it is recognized as an audio: by the extension in the link, by the Content-Type: audio/* header in the server response or by the file contents. The contact sees it as a recorded voice message. Audio files in the MP4 or M4A (AAC) format are supported.

An instance authorized with an imported browser session cannot send voice messages.

Request#

To send a file by a link, you have to execute a request at:

POST
{{apiUrl}}/waInstance{{idInstance}}/sendFileByUrl/{{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
urlFile string Yes The link to the file to send
quotedMessageId string No The identifier of the quoted message
When the parameter is filled in, the message is sent as a quote of the specified chat message.
Specify a message of the same chat
sendAsVoice boolean No Send the file as a voice message even if it is not recognized as an audio by the link. The default is false

The caption, fileName, archive, typingTime and typingType fields may be passed, but the method does not use them: no caption is sent with the file.

Request body example#

Sending an image:#

{
    "chatId": "49547665464",
    "urlFile": "https://example.com/photo.jpg"
}

Sending a video by username:#

{
    "chatId": "@green_api",
    "urlFile": "https://example.com/clip.mp4"
}

Sending a voice message:#

{
    "chatId": "49547665464",
    "urlFile": "https://example.com/voice.m4a",
    "sendAsVoice": true
}

Response#

Response parameters#

Field Type Description
idMessage string The identifier of the sent message

Response body example#

{
    "idMessage": "32992354910263051384774140624896000"
}

SendFileByUrl 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:
'urlFile' is required
The link to the file is not passed
400 Validation failed. Details:
'urlFile' must be a valid uri with a scheme matching the http\|https pattern
The link must start with http:// or https://
400 Validation failed. Details:
'quotedMessageId' must be the numeric message id
The quotedMessageId parameter must contain digits only
400 'urlFile' must be an MP4/M4A (AAC) audio file to be sent as a voice message A file for a voice message must be in the MP4 or M4A (AAC) format
400 urlFile https://example.com/photo.jpg: cannot be downloaded (HTTP 404) The file cannot be downloaded from the link: the server has answered with an error, its code is shown in brackets
400 urlFile https://example.com/photo.jpg: file cannot be downloaded The file cannot be downloaded from the link: the server is unavailable
422 SendFileByUrl: not available for a web session The instance is authorized by importing a browser session: such an instance does not send voice messages
502 sendFileByUrl failed The file has not been sent. Check that the file is available at the link and repeat the request later

Request examples#

import requests

url = "{{apiUrl}}/waInstance{{idInstance}}/sendFileByUrl/{{apiTokenInstance}}"

payload = {
    "chatId": "49547665464",
    "urlFile": "https://example.com/photo.jpg"
}
headers = {'Content-Type': 'application/json'}

response = requests.post(url, json=payload, headers=headers)

print(response.text.encode('utf8'))
<?php
$url = '{{apiUrl}}/waInstance{{idInstance}}/sendFileByUrl/{{apiTokenInstance}}';

$data = array(
    'chatId' => '49547665464',
    'urlFile' => 'https://example.com/photo.jpg'
);

$options = array(
    'http' => array(
        'header' => "Content-Type: application/json\r\n",
        'method' => 'POST',
        'content' => json_encode($data)
    )
);

echo file_get_contents($url, false, stream_context_create($options));
?>
curl --location '{{apiUrl}}/waInstance{{idInstance}}/sendFileByUrl/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "chatId": "49547665464",
    "urlFile": "https://example.com/photo.jpg"
}'
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/sendFileByUrl/")
    .append({{apiTokenInstance}});

var response = Unirest.post(requestUrl.toString())
    .header("Content-Type", "application/json")
    .body("""
        {
            "chatId": "49547665464",
            "urlFile": "https://example.com/photo.jpg"
        }
        """)
    .asString();

System.out.println(response);