JSON in Webhook notification

I’ve setup a StatPing which has webhook notification functionality. I can successfully trigger a webhook in HA but finding it hard to use the json from the payload in my messages. Here is the payload and my code:

Payload:

{
  "id": "{{.Service.Id}}",
  "online": true
}

Automation:

- id: '1593508230036'
  alias: Statping Test
  description: ''
  trigger:
  - platform: webhook
    webhook_id: ID12345
  condition: []
  action:
  - data_template:
      message: '{{ trigger.json.id }} is {{ trigger.json.online}}'
      title: Test
    service: persistent_notification.create

Error in HA:

Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'json'

I’ver followed the templating guide which states the use of trigger.json and using data_template but still get the above error.

Any ideas?

The payload has to be posted as JSON. It could also be Form-data. That depends on how the data is pushed. Make sure it’s the correct format.

From the information within Statping it does show as JSON.

Now I’m getting the following error:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/webhook/__init__.py", line 97, in async_handle_webhook
    response = await webhook["handler"](hass, webhook_id, request)
  File "/usr/src/homeassistant/homeassistant/components/automation/webhook.py", line 30, in _handle_webhook
    result["json"] = await request.json()
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_request.py", line 584, in json
    return loads(body)
  File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Ok so it looks like whatever Statping is sending its not JSON formatted as I’ve tested in Node-Red (thanks to @Villhellm) and the following flow works:

[{"id":"d3666d4a.9dd568","type":"inject","z":"67140efa.120ab","name":"","topic":"","payload":"{ \"service\": \"Test\",\"status\": \"Online\" }","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":450,"y":2020,"wires":[["e2513fc1.ea6d5"]]},{"id":"e2513fc1.ea6d5","type":"http request","z":"67140efa.120ab","name":"webhook","method":"POST","ret":"txt","paytoqs":false,"url":"http://192.168.1.12:8123/api/webhook/ID12345","tls":"","persist":false,"proxy":"","authType":"","x":640,"y":2020,"wires":[[]]}]

I’ll reach out to Statping and see if they can shed some light on the issue.

Looking at Statping logs its showing that the correct JSON was sent so not sure what’s going on:

e[36mINFOe[0m[243745] sending body: '{   "service": "Another Test","status": "Online" }' to http://192.168.1.12:8123/api/webhook/ID12345 as a POST request 
e[36mINFOe[0m[243745] /api/notifier/webhook/test (POST) | IP: 192.168.1.12:32813  e[36mload_micro_secondse[0m=7762 e[36mmethode[0m=POST e[36mtypee[0m=handlers e[36murle[0m=/api/notifier/webhook/test