Search code examples
curlmultipartform-datatelegram-bot

Posting a file via curl to the telegram bot api


I've tried the following:

curl -F name=document -F upload=@<path_to_the_file> \ 
     -H "Content-Type:multipart/form-data" \ 
     "https://api.telegram.org/bot<token>/sendDocument?chat_id=<chat_id>"

It returns {"ok":false,"error_code":400,"description":"[Error]: Bad Request: there is no document in request"}

What have I done wrong?

Here is some documentation on sendDocument method.


Solution

  • Hope this helps. Note that there is "bot" before <token>.

    curl -F document=@"path/to/some.file" https://api.telegram.org/bot<token>/sendDocument?chat_id=<chat_id>