Problems converting webhook to JSON object

Hello all.

I suppose I should mention that I am quite new to Node-RED. :slight_smile:

I have a webhook from Plex being sent to Node-RED via http://webhookrelay.com. I have the connector node working, and RED is receiving messages, but I am having trouble with the message that is being received from webhook-relay. The message comes in as a JSON object, which I believe is a wrapper from webhook-relay.

Debug Output

21/12/2021, 16:45:34node: webhook_dbg
plexbucket : msg.payload : Object
object
type: "webhook"
meta: object
id: "##############################"
bucked_id: "##############################"
bucket_name: "plexbucket"
input_id: "##############################"
input_name: "Default public endpoint"
output_name: ""
output_destination: ""
headers: object
Accept: array[1]
0: "*/*"
Accept-Encoding: array[1]
0: "gzip"
Content-Length: array[1]
0: "12062"
Content-Type: array[1]
0: "multipart/form-data; boundary=------------------------c7b26957a9fb7c1b"
User-Agent: array[1]
0: "##############################"
query: ""
body: "--------------------------c7b26957a9fb7c1b↵Content-Disposition: form-data; name="payload"↵Content-Type: application/json↵↵{"event":"media.scrobble","user":true,"owner":true,"Account":{"id":1,"thumb":"##############################","title":"######"},"Server":{"title":"################","uuid":"############################"},"Player":{"local":true,"publicAddress":"###.###.###.###","title":"Microsoft Edge","uuid":"##############################"},"Metadata":{"librarySectionType":"show","ratingKey":"16633","key":"/library/metadata/16633","parentRatingKey":"16632","grandparentRatingKey":"16631","guid":"plex://episode/616457d0dcafa2bcb75c96db","parentGuid":"plex://season/61651249024c21eb63bf0a9e","grandparentGuid":"plex://show/616457cedcafa2bcb75c96b1","type":"episode","title":"Episode 1","grandparentKey":"/library/metadata/16631","parentKey":"/library/metadata/16632","librarySectionTitle":"TV","librarySectionID":2,"librarySectionKey":"/library/sections/2","g..."
method: "POST"

However, I am having trouble parsing out the BODY part of the message in to its own object for use in other thing like functions and switches. The content of body should already contain JSON data, which I hope to use in a switch...

[{"id":"db306fc76c716133","type":"switch","z":"f6f2187d.f17ca8","name":"Media Function","property":"payload.body.event","propertyType":"msg","rules":[{"t":"eq","v":"media.pause","vt":"str"},{"t":"eq","v":"media.play","vt":"str"},{"t":"eq","v":"media.rate","vt":"str"},{"t":"eq","v":"media.resume","vt":"str"},{"t":"eq","v":"media.scrobble","vt":"str"},{"t":"eq","v":"media.stop","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":480,"y":260,"wires":[["acd8d7b6e0288518"],["acd8d7b6e0288518"],["acd8d7b6e0288518"],["acd8d7b6e0288518"],["c68cd89e5eacced5","acd8d7b6e0288518"],["acd8d7b6e0288518"]]}]

But the switch does not appear to respond to msg.payload.body.

I've tried running msg.payload.body through a JSON node...

[{"id":"96f5b34c29df3823","type":"json","z":"f6f2187d.f17ca8","name":"","property":"payload.body","action":"","pretty":true,"x":680,"y":780,"wires":[["66448228366602c1"]]}]

But all I get out of it is a string, containing the JSON Data, and I'm at a loss on how to get this as a usable object.

(Also, as an aside. I've also tried configuring direct input from Plex Webhook using a HTTP-IN node, but all I get I gibberish (a buffer msg.payload with hex values :confused: )

Any pointers or advice to remedy this would be greatly appreciated :slight_smile:

H

If you just want to work with the content of the msg.payload.body < that is how you would use it in a function or switch node.

A switch node is used for routing messages to different nodes, it does not modify the message contents.

Make sure to go through the documentation that covers all these subjects.

What are you trying to accomplish ?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.