REST api responds with 400 Bad Request but no debugging info anywhere

Hi! I need to get some data into HomeAssistant from some routines running on my Raspberry Pi. I figured using curl to connect to the REST api would be easiest, as this interaction only needs to be in one way. Specifically, I need to get some data into input_text and input_datetime helpers.

Wrote a shell script with a curl command, but got back 400 Bad Request. Moved everything over to Postman for easier debugging but still, I get 400 on everything I try regarding the input helpers. What’s driving me nuts is that there is no logging going on, anywhere. However before, I made a mistake in authentication (bearer with lower case instead of upper) and I did get a 401 error in the logs. Also: light/turn_on and light/turn_off do seem to work. So I’m assuming my base url, headers and authentication are correct.

This is my request:

URL: http://192.168.1.3:8123/api/services/input_text/set_value

Authorization: Bearer ******
Content-Type: application/json

Body: {"data":"Anyone there?","entity_id":"input_text.test"}

Now I’m just baffled. Same JSON format on lights on service works fine, but not on Input helper. I also see a lot of topics regarding the same issue: some unexplainable 400 response. Wouldn’t be much of a problem is there was actually a place to find a debug log.

Edit: I’m aware of being able to set the state of an entitiy directly. Got that working somewhere else, but I need to use templates in one of them and I can’t get that to work with this states/X endpoint. Also I just want to know how to debug those damn calls.

An error 400 indicates a wrong request on the client side.
There is probably no debugging info, because the server have no clue what you tried to do.

A server will not just ‘have no clue’. A server can for instance…

  • Be unable to parse the message (why? it’s valid JSON)
  • Not understand the endpoint (which should return 404)
  • Decide the request is invalid (which would imply a reason)
  • Lack information (it should tell me what it’s missing)

This is the equivalent of someone coming onto a support form saying “it’s not working”. Surely there’s more info than that, so just print it somewhere.

If it’s a malformed syntax, which usually is (should be) the case for 400 errors, there is also an error message. Assuming HA uses Python JSON decoder, that decoder will just state what is missing and at what position and there is no reason to not put that in the reply or at least log it somewhere.

No useful tool in programming is going to output “Nah, wrong.”.

Sure, but when support ask you what you want then you say “I work on the file”.
If you do not have a valid context then there is no way to know what “work on the file is” or “what type of file it is”, so the request is invalid, which is actually what a error 400 is. Of course you could get a message saying “invalid request”, but that is what error 400 means and it would not make you any wiser.

Your JSON looks fine in the syntax, but it might still not make sense in the context.

What I am trying to say is that you need to either find the documentation for the rest API service call or wait for someone with the knowledge about that subject.
The server can not help you.

That all implies the server has more information about what is wrong. A missing context is more useful (and questionable as I’ve described the context in the endpoint, and if that’s wrong, it should say something like unknown endpoint and throw 404). If the server ‘can’t help it’, that’s shitty server design. The server obviously can’t fix it for me, I get that, but a functional server should describe what is missing.

Just like when you fire a service call through the UI and you get the data wrong. There’s error messages for that, whether it’s syntax, format or missing or incorrect arguments.

Also documentation on this gives no info whatsoever about debugging.