I spent way to much time trying to figure out why webhooks form Plex media server were not easy to parse and also why I was getting Webhook: Error delivering payload, error 408 form Plex.
First – I am using a “http in” node to receive the web hook. Every “http in” web hook eventually needs a http response node attached to it so the connection will close. Without the http response node the connections will stack up and eventually start hitting some ceiling in the number of open connections which causes the 408 error. I just send back a http 200 response and connect it directly to the http in node so the processing down the line does not affect how fast the connection is closed.
Next problem was trying to figure out why I could not parse the JSON payload in the webook. I finally figured out that the “payload” from Plex is encoded in the msg.payload.payload property, so I think Plex is creating a JSON object with the top level property being “payload” and then the other properties fall below that. So, kind of a cluster and means that the JSON string is just passed through the http in instead of being parsed.
To parse the JSON from the Plex webhook you just need to add a “json” parse node and set the property to parse as “msg.payload.payload”.
You would be fine here to then start building out your other nodes and when you need a property value from the payload you could reference it by going deep, so for instance to get the event property value you could use msg.payload.payload.event and get the event value.
If this bothers you, like it did me you can re-assign the msg.payload property to equal msg.payload.payload by using a “change” node to set msg.payload to msg.payload.payload. Then you can reference the event like msg.payload.event instead of doubling up on “payload”. It just looks cleaner.
Your full block might look something like this. Sky’s the limit with Node Red of course.