RESTful command and templated url problem

Hi,

I’m trying to post a simple http command to a device with a RASTful command but fail to get the variables through to url;

rest_command:
  set_garo_timer:
    url: http://192.168.0.230:80/v1/timer/{{ id }}
    method: POST
    payload: 'test'
    verify_ssl: false

When calling this from dev tools services with {id:"0"} as data, I get in log:

Error 404 on call http://192.168.0.230:80/v1/timer/.

Also, the payload does not seem to appear there.

Any Advice, please?

Oh, this is with Hassio 0.101.3.

That’s an easy one: You can’t use templates in the services dev tools.

Wait. I think I misunderstood. This should work. I actually do something very similar. Can you screenshot your dev services page?

Sure, here you go:

The code in configuration.yaml:

rest_command:
  test_call:
    url: "http://192.168.0.230:80/v1/timer/{{ id }}"
    method: POST
    payload: 'Testing it'
    verify_ssl: false

And the corresponding line in the log:

2019-11-15 09:17:44 WARNING (MainThread) [homeassistant.components.rest_command] Error 404 on call http://192.168.0.230:80/v1/timer/.

I’d expect the log to have
http://192.168.0.230:80/v1/timer/0.

I have a very similar rest_command:

rest_command:
  slack_api:
    url: https://slack.com/api/{{ api }}
    content_type: 'application/json; charset=utf-8'
    verify_ssl: true
    method: 'post'
    timeout: 20
    headers:
      Authorization: !secret slackbot_token
    payload: '{{ payload }}'

I can call the service from the dev page like this:
image

And I get a message in the logs like this:
2019-11-15 08:26:03 INFO (MainThread) [homeassistant.components.rest_command] Success call https://slack.com/api/chat.postMessage.

So, in short, the only differences I can see between what I have and what you’re doing are:

  1. The way we quote things (which I think is a red herring)
  2. The way we write data into the template dev tool.

I’m also not sure if entering ‘0’ without quotes makes it be treated as an integer. Can you try specifying the data for the service as

id: "0"

and see if that works?

Ah, turned out it’s not the quotes but the (missing) space after the colon on the data input.
so {id: 0} instead of {id:0}.

1 Like