sendPhoto
Send a photo to a specified chat. Supports uploading a file directly or passing a file_id of a previously uploaded file.
Request
POST /:token/sendPhoto
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 |
| photo | String/File | Yes | Photo file or file_id of a previously uploaded file, max 10MB |
| caption | String | No | Photo 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": 101,
"from": {
"id": 123456789,
"is_bot": true,
"first_name": "MyBot",
"username": "my_bot"
},
"chat": {
"id": 987654321,
"first_name": "User",
"username": "user123",
"type": "private"
},
"date": 1700000000,
"photo": [
{
"file_id": "AgACAgIAAxkBAAI...",
"file_unique_id": "AQADAgAT...",
"file_size": 12345,
"width": 320,
"height": 240
},
{
"file_id": "AgACAgIAAxkBAAI...",
"file_unique_id": "AQADAgAT...",
"file_size": 56789,
"width": 800,
"height": 600
}
],
"caption": "This is a sample photo"
}
}Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters, e.g. unsupported file format or exceeds size limit (max 10MB) |
| 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 |
| 500 | Internal server error |
Examples
Send Photo via File Upload
bash
curl -X POST "https://api.example.com/<token>/sendPhoto" \
-F "chat_id=987654321" \
-F "photo=@/path/to/image.jpg" \
-F "caption=This is a sample photo"Send Photo via file_id
bash
curl -X POST "https://api.example.com/<token>/sendPhoto" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"photo": "AgACAgIAAxkBAAI...",
"caption": "Forwarding a photo"
}'