sendDocument
Send a document file to a specified chat. Supports uploading a file directly or passing a file_id of a previously uploaded file. Suitable for sending files of any type, with a maximum size of 100MB.
Request
POST /:token/sendDocument
Use multipart/form-data encoding for file uploads.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Unique identifier or username of the target chat |
| document | String/File | Yes | Document file or file_id of a previously uploaded file, max 100MB |
| caption | String | No | Document caption text |
| parse_mode | String | No | Parsing mode for the caption, supports HTML or Markdown |
| reply_markup | Object | No | Custom keyboard or inline keyboard markup, JSON-serialized object |
| reply_to_message_id | Integer | No | ID of the message to reply to |
Response
Returns the sent Message object on success.
json
{
"ok": true,
"result": {
"message_id": 105,
"from": {
"id": 123456789,
"is_bot": true,
"first_name": "MyBot",
"username": "my_bot"
},
"chat": {
"id": 987654321,
"first_name": "User",
"username": "user123",
"type": "private"
},
"date": 1700000000,
"document": {
"file_id": "BQACAgIAAxkBAAI...",
"file_unique_id": "AQADAgAT...",
"file_name": "report.pdf",
"mime_type": "application/pdf",
"file_size": 524288
},
"caption": "This is a report document"
}
}Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters, e.g. missing document or chat_id |
| 401 | Invalid or expired token |
| 403 | Bot does not have permission to send messages to this chat |
| 404 | Chat not found |
| 413 | File too large (exceeds 100MB) |
| 500 | Internal server error |
Examples
Send Document via File Upload
bash
curl -X POST "https://api.example.com/<token>/sendDocument" \
-F "chat_id=987654321" \
-F "document=@/path/to/report.pdf" \
-F "caption=This is a report document"Send Document via file_id
bash
curl -X POST "https://api.example.com/<token>/sendDocument" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"document": "BQACAgIAAxkBAAI...",
"caption": "Forwarding a document"
}'