Nicolas Raoul
Nicolas Raoul

Reputation: 60213

Bad Request when sending POST /messages to Let's Chat API

I am trying to create a bash/curl script that sends a message to a Let's Chat server.

The API works fine for reading messages:

$ curl --user `cat token.txt`:abc \  
    http://192.168.0.1:5000/rooms/slugsample/messages
[{"id":"559cf90802b85abb776a307b","text":"Salut [...]

Unfortunately it does not seem to work to send a new message:

$ curl --data '{"text":"Hello"}' --user `cat token.txt`:abc \  
    http://192.168.0.1:5000/rooms/slugsample/messages
Bad Request

What am I doing wrong?

curl 7.38.0
Let's Chat 0.4.0

Upvotes: 0

Views: 836

Answers (1)

Peter Hauge
Peter Hauge

Reputation: 747

You may want to specify that the content type is JSON. Curl allows you to add header information with the -H option.

curl -H "Content-Type: application/json" -X POST -d '{"text":"Hello"}' \
http://192.168.0.1:5000/rooms/slugsample/messages --user `cat          \
token.txt`:username                                          

Edit

I spinned up a Let's Chat Docker container and confirmed that the above curl works.

I also got a HTTP Error - 400 Bad Request when I did NOT include the -H "Content-Type: application/json"

Upvotes: 1

Related Questions