Skip to content

SendFileByUpload#

Beta version

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

The method is used to send a file uploaded through a form (form-data).

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 with the audio/* MIME type is sent as a voice message: 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, you have to execute a request at:

POST
{{mediaUrl}}/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}

For mediaUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.

The request body is passed in the multipart/form-data format.

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
file file Yes An image, video or audio file
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

Response#

Response parameters#

Field Type Description
idMessage string The identifier of the sent message
urlFile string Link to the uploaded file. The file is stored for 15 days: after that the link stops working

Response body example#

{
    "idMessage": "32992354910263051384774140624896000",
    "urlFile": "https://storage.yandexcloud.net/sw-media/5100000000/9b1f4c2e-6d3a-4e8b-a0c7-2f5e8d1b3a64.jpg"
}

SendFileByUpload 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:
'file' is required
The file is not attached to the request
400 Validation failed. Details:
'file' should not be empty
The attached file is empty
400 Validation failed. Details:
'quotedMessageId' must be the numeric message id
The quotedMessageId parameter must contain digits only
400 'file' 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
413 'file' is larger than the upload limit The file size exceeds the allowed limit
422 SendFileByUpload: not available for a web session The instance is authorized by importing a browser session: such an instance does not send voice messages

Request examples#

import requests

url = "{{mediaUrl}}/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}"

payload = {'chatId': '49547665464'}
files = [
    ('file', ('photo.jpg', open('photo.jpg', 'rb'), 'image/jpeg'))
]

response = requests.post(url, data=payload, files=files)

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

$post = array(
    'chatId' => '49547665464',
    'file' => new CURLFile('photo.jpg', 'image/jpeg', 'photo.jpg')
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

echo curl_exec($ch);
curl_close($ch);
?>
curl --location '{{mediaUrl}}/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}' \
--form 'chatId="49547665464"' \
--form 'file=@"photo.jpg"'