Krishan Chawla

Back

Telegram Bot APIs

Quick-access to Telegram Bot APIs plus common troubleshooting steps.

✈️ Telegram snippet

Telegram Bot API — DevTools#

A complete reference of raw Telegram Bot API commands, cURL examples, Java integration, and error fixes.


Send a Simple Text Message#

curl -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage" \
  -d "chat_id=<CHAT_ID>" \
  -d "text=Hello from my DevTools!"
bash

Send Markdown Message#

curl -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage" \
  -d chat_id=<CHAT_ID> \
  -d parse_mode="Markdown" \
  -d text="*Bold text* _Italic text_"
bash

Send Photo (URL)#

curl -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/sendPhoto" \
  -d chat_id=<CHAT_ID> \
  -d photo="https://example.com/image.png"
bash

Send Local Photo#

curl -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/sendPhoto" \
  -F chat_id=<CHAT_ID> \
  -F photo=@"/path/to/local/image.png"
bash

Send Document (PDF, ZIP, Logs)#

curl -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/sendDocument" \
  -F chat_id=<CHAT_ID> \
  -F document=@"/path/to/file.pdf"
bash

Quick GET Request (Browser Friendly)#

https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage?chat_id=<CHAT_ID>&text=Hello
plaintext

Java Snippets (Without telegrambots Library)#

Java: Send Text Message#

String token = "<YOUR_TOKEN>";
String chatId = "<CHAT_ID>";
String text = "Hello from Java!";

String url = "https://api.telegram.org/bot" + token +
             "/sendMessage?chat_id=" + chatId +
             "&text=" + URLEncoder.encode(text, "UTF-8");

HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod("GET");

int responseCode = conn.getResponseCode();
System.out.println("Response Code: " + responseCode);
java

Java: Send Photo (Multipart Upload)#


Error Fixes#

401 Unauthorized#

Fix:

  • Wrong bot token
  • Wrong chat_id
    Check updates:
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
bash

400 Bad Request: chat not found#

Fix:

  • User has not clicked Start
  • Bot not added to group
  • For groups: chat ID must be negative

Example:

-987654321
plaintext

Java Proxy Fix#

System.setProperty("http.proxyHost", "proxy.company.com");
System.setProperty("http.proxyPort", "8080");
java

Variable Reference#

<YOUR_TOKEN> → Telegram Bot Token  
<CHAT_ID> → User ID / Group ID / Channel ID  
Group IDs → Negative (e.g., -123456789)
plaintext
Published: 12/9/2025

Back to DevTools