Telegram Bot API
🌐 English

setWebhook

Category: Updates · Bot API 10.3 · Official documentation

Sets a webhook.

Returns: On success, returns True.

Parameters

ParameterTypeRequiredDescription
urlStringYesWebhook URL (empty string = delete)
certificateInputFileOptionalPublic key certificate (for self-signed)
ip_addressStringOptionalIP address for webhook
max_connectionsIntegerOptionalMax connections (1-100, default 40)
allowed_updatesArray of StringOptionalJSON array of update types
drop_pending_updatesBooleanOptionalDrop pending updates
secret_tokenStringOptionalSecret token for X-Telegram-Bot-Api-Secret-Token

Parameter descriptions are concise summaries; see the official documentation for the full text.

Example request

curl

curl -s -X POST "https://api.telegram.org/bot$TOKEN/setWebhook" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/telegram/webhook"}'

Python

import requests

TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
    f"https://api.telegram.org/bot{TOKEN}/setWebhook",
    json={
        "url": "https://example.com/telegram/webhook"
    },
    timeout=30,
)
print(resp.json())

JavaScript

const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/setWebhook`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "url": "https://example.com/telegram/webhook"
  }),
});
console.log(await res.json());

Step-by-step guide: How to Set Up a Telegram Bot Webhook: setWebhook, Secret Token and Troubleshooting