Can't make rest command to work

hi I’m trying to make this work :

  feedings2:
    url: "https://bonneaubabybuddy.herokuapp.com/api/feedings"
    method: post
    headers:
      authorization: Token [MYTOKEN]
    payload: '{"child":"1", "start":"2022-09-22T19:50:00-04:00", "end": "2022-09-22T19:53:00-04:00", "type": "formula", "method":"bottle"}'
    content_type: "application/json"

I know that is supposed to work since I tested it with https://reqbin.com

what I’m I doing wrong ? is it possible to see some log of that ?

Thanks

In configuration.yaml


logger:  
  default: info
  logs:
    homeassistant.components.rest_command: debug
    homeassistant.components.rest.data: debug
   

I found the issu thank ! but I can’t find how to resolve it … in the log I can see :

2022-09-24 16:25:56.454 DEBUG (MainThread) [homeassistant.components.rest_command] Success. Url: https://bonneaubabybuddy.herokuapp.com/api/feedings/. Status code: 200. Payload: b"{‘child’: ‘1’, ‘start’: ‘2022-09-22T19:50:00-04:00’, ‘end’: ‘2022-09-22T19:53:00-04:00’, ‘type’: ‘formula’, ‘method’: ‘bottle’}"

why is there a “b” after payload ? I tried think like payload: "{{ payload_data }}" but the “b” remain…

I found this post with the same issue and they found an alternative way to do it but I don’t know how to do it with my rest command :

https://community.home-assistant.io/t/build-rest-command-to-send-data-to-abetterrouteplanner-com/307380/2

1 Like

Why do you think it isn’t working?

Your log doesn’t have an error. Status code 200 means success (it also says it there).

The b is Python’s way of just saying the payload is a string of bytes (so it can contain any binary data).

It’s supposed to to respond a 201 (created )

Token would typically be Bearer in case of using a bearer token. It’s not clear whether you actually have Token in there, before the actual token, or whether you redacted more of that part.

Could you use ReqBin again and let it generate the curl code for your request (and redact your token again), so that one can compare exactly?

Also, no docs from the site/app you’re using, so hard to check anything else, but maybe there’s another header required (ReqBin by default has headers that you don’t have in your YAML, hence the need to see exactly what you tested).

Hi, Thank you to try to help me ! I did fix it this night but I can’t tell how … I copy paste the code off some one else and change only my url and token and it worked…the code looked the same but there is probably a little something that I didn’t see

Thanks again

1 Like

I’m having a similar error of malformed payload and seeing a suspicious “b” in the log…

Status code 422. Payload: b'{"ttl":600,"data": "redactedIP"}'

Would you be able to copy-paste your rest_command by any chance?
Thanks

Rather than using ReqBin, I’d suggest running the command via a terminal in HA. That way you know there are no hidden headers, and if there’s something specific to your HA environment that’s making it fail, you’ll see that in the output.