Getting 400 error when sending custom keyboard through Telegram bot sendMessage endpoint

I’m trying to send a message with a custom keyboard using the Telegram bot API but I keep getting a 400 HTTP error. Here’s the JSON payload I’m using:

{
  "chat_id": 248901234,
  "text": "Choose your preferred language",
  "reply_markup": {
    "keyboard": [
      [{"text": "English"}, {"text": "German"}],
      [{"text": "French"}, {"text": "Russian"}],
      [{"text": "Italian"}, {"text": "Spanish"}]
    ]
  }
}

When I send this as a POST request to the sendMessage method, it returns a 400 bad request error. The keyboard structure looks correct to me but something must be wrong. Has anyone encountered this issue before? What could be causing this error with the keyboard markup?

Had the same issue with my first Telegram bot. You probably need to set “one_time_keyboard”: false to keep the keyboard visible, or true to hide it after someone taps it. Some API versions throw validation errors without this parameter. Also check your chat_id - I’ve gotten 400 errors when the user hasn’t started the bot yet or the chat_id format’s wrong. Send a plain text message first to test the chat_id, then add the keyboard back.

youre missing resize_keyboard in your reply_markup. try adding "resize_keyboard": true. that should solve the 400 error. also, double check ur bot token in the request URL. hope this helps!

Your keyboard parameter structure is the problem. Wrap your keyboard array in a ReplyKeyboardMarkup object and format it properly:

"reply_markup": {
  "keyboard": [
    [{"text": "English"}, {"text": "German"}],
    [{"text": "French"}, {"text": "Russian"}],
    [{"text": "Italian"}, {"text": "Spanish"}]
  ],
  "one_time_keyboard": true
}

I hit this same issue last month - adding one_time_keyboard fixed it. Also check that you’re sending the request with Content-Type: application/json. Those 400 errors usually happen when the API can’t parse your JSON structure.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.