Webhook Notifications

I’ve had a earlier automation that sends a webhook when the alarm is triggered that looks like this:

automation:
- alias: 'Alarm triggered (send to safe.land)'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.ha_alarm
      to: 'triggered'
  action:
    - service: rest_command.safe_land

And the rest command is just a simple:

rest_command:
  safe_land:
    method: POST
    url: !secret safeland_hook
    verify_ssl: false
    content_type:  'application/json; charset=utf-8'

That works just great but I’m trying to setup Alarmo and wanted to use the notify function so I read up about it in the docs and made a notification client that looks like:

notify:
  - name: safeland
    platform: rest
    method: POST
    verify_ssl: false
    content_type:  'application/json; charset=utf-8'
    resource: !secret safeland_hook

But when I try the notification I keep getting a 400 or 405 error depending on use of the “method”

2021-01-09 13:43:27 ERROR (SyncWorker_21) [homeassistant.components.rest.notify] Client error. Response 400: :
NoneType: None
2021-01-09 13:51:27 ERROR (SyncWorker_20) [homeassistant.components.rest.notify] Client error. Response 405: :
NoneType: None
2021-01-09 13:53:47 ERROR (SyncWorker_23) [homeassistant.components.rest.notify] Client error. Response 405: :
NoneType: None
2021-01-09 14:02:17 ERROR (SyncWorker_15) [homeassistant.components.rest.notify] Client error. Response 400: :
NoneType: None

Any ideas why it’s not working?

It might be because the notify.rest service needs headers to be passed as a string:

notify:
  - name: safeland
    platform: rest
    method: POST
    verify_ssl: false
    headers: 'content-type: application/json; charset=utf-8'
    resource: !secret safeland_hook

(for reference, “400” is “Bad request”, “405” is “Method not allowed”)

Thanks, tried that now but got a error that
Invalid config for [notify.rest]: expected a dictionary for dictionary value @ data['headers']. Got 'application/json; charset=utf-8'.

Changed it to this instead:

  - name: safeland
    platform: rest
    method: POST
    verify_ssl: false
    headers: 
      content-type: 'application/json; charset=utf-8'
    resource: !secret safeland_hook

but then I got a 400 response again so tried commenting out the “header” row instead, thought maybe that would work since it’s optional but that still gives me a 400

Thanks for the info about 400/405. 400 is what I get when using “post” and 405 for “get” so the first should be the right method anyway.

The webhook url is https so verify_ssl: false should still be there and the rest seems correct! Not critical since I can still use a standard automation but would be fun to figure out why!
Could the problem be it tries to send a message to a webhook?

Ah, in that case the fine manual is wrong :woozy_face:

Possibly. If you can run something like cURL easily, you could try and see whether it’s failing on data being passed:

curl -XPOST -d 'some data' -H'content-type: application/json; charset=utf-8' URL

Or use a tool like Postman instead of cURL.

yup that seems to be it, sending with the -d 'some data' switch it doesn’t work but when I removed that and sent it with curl it triggered the event as it should.