Struggling to get actionable push notifications working

I’m trying to get html5 push notification working with Node Red. I’m using the example in the HA Push Notification page:

message: Anne has arrived home
data:
  actions:
    - action: open
      icon: "/static/icons/favicon-192x192.png"
      title: Open Home Assistant
    - action: open_door
      title: Open door

converted to json…

{
  "message": "Anne has arrived home",
  "data": {
    "actions": [
      {
        "action": "open",
        "icon": "/static/icons/favicon-192x192.png",
        "title": "Open Home Assistant"
      },
      {
        "action": "open_door",
        "title": "Open door"
      }
    ]
  }
}

which works when pasted in the data field of a call service node calling notify.push BUT when I try to put it in a function node before the call service node, I get

Call-service API error.  Error Message: extra keys not allowed @ data['actions']

and for the life of me I can’t figure out why.

My flow is:

[{"id":"90ca26d7.46d8b8","type":"api-call-service","z":"8003659f.904cb8","name":"","server":"9133f0de.c8669","version":1,"debugenabled":true,"service_domain":"notify","service":"push","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":560,"y":1020,"wires":[[]]},{"id":"3ff76305.56be1c","type":"inject","z":"8003659f.904cb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":860,"wires":[["4e6f41f9.4660a"]]},{"id":"4e6f41f9.4660a","type":"function","z":"8003659f.904cb8","name":"","func":"msg.payload = \n{\n  \"message\": \"Anne has arrived home\",\n  \"data\": {\n    \"actions\": [\n      {\n        \"action\": \"open\",\n        \"icon\": \"/static/icons/favicon-192x192.png\",\n        \"title\": \"Open Home Assistant\"\n      },\n      {\n        \"action\": \"open_door\",\n        \"title\": \"Open door\"\n      }\n    ]\n  }\n}\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":940,"wires":[["90ca26d7.46d8b8"]]},{"id":"9133f0de.c8669","type":"server","z":"","name":"Home Assistant"}]

Can anyone help me please?

Thanks,

Matt

I had a quick look at docs so not really sure can you try nesting data one more level

"data":
  "data":
    "actions":
  ....

Thanks for the response. I’ve tried it as follows but it still fails

{
  "message": "Anne has arrived home",
  "data": {
    "data": {
      "actions": [
        {
          "action": "open",
          "icon": "/static/icons/favicon-192x192.png",
          "title": "Open Home Assistant"
        },
        {
          "action": "open_door",
          "title": "Open door"
        }
      ]
    }
  }
}
Call-service API error.  Error Message: required key not provided @ data['message']

Ok so now move the msg inside the first data level. See if that works, at least the error is complaining about that.

Bingo!! That worked, thank you so much…

{
  "data": {
    "message": "Anne has arrived home",
    "data": {
      "actions": [
        {
          "action": "open",
          "icon": "/static/icons/favicon-192x192.png",
          "title": "Open Home Assistant"
        },
        {
          "action": "open_door",
          "title": "Open door"
        }
      ]
    }
  }
}
3 Likes