Node Red - Webhook

other-dev

#1

Hello,
I want to use the Webhooks in Node-red. But for this to be used i need the payload as JSON.
I tried setting up a webhook with the http in node, a debug node and a http response node.
But the result i get is not parsed as JSON.
Can anyone setup a example Node red flow that parses the payload of the post to readable JSON format.?


#2

Hi,
It seems that this implementation doesn't work because the POST is multi part body.
What I've tested and works is to use this node httpInMultipart
The response of this node can be afterwards processed like this:
json = JSON.parse(msg.payload.payload);


#3

ah oke.. what did you fill in the fields input field?


#4

I've tried several things, but in the end I put only:
[]


#5

Yes that works partly. I got the message: "Error: Unexpected field" when media.play is send in debug panel. But for the media.stop event i see the whole json in the debug panel.


#6

You're right, I didn't observe it.
I don't know if this is an issue from Plex or with the node.


#7

My colleague came up with this solution, works for me:

var json = msg.payload.toString();
var startPosition = json.indexOf(’{’);
json = json.substr(startPosition);

var endPosition = json.indexOf("
–");
json = json.substr(0, endPosition);

msg.payload = json;

return msg;


#8

This is it. Thanks


#9

Hi,

I’m trying to get the Webhooks of Plex working with Node-Red but cannot for the life of me get it to work.

Here’s my setup:

Plex server is installed on my Windows 10 PC.
Node-Red is installed on a Beaglebone Black (BBB).

In the plex settings I have set the Webhook to point the IP address of the BBB including various ports/folders etc like:

http://192.168.1.251:12000
http://192.168.1.251:12000/plex
http://192.168.1.251/plex
http://192.168.1.251

and have tried multiple configurations of the http in node and the Websocket in node in Node-Red but without success.

Can someone point to where I may be going wrong please.

Thanks


#10

Hi,

My implementation looks like below:

So ‘/plex’ is enough for URL and set ‘POST’ for Method.

But before that you can try something simpler, make an additional flow, we’re you have an ‘http in’, connected to ‘http respone’ and ‘debug’. For the ‘http in’ set ‘GET’ and ‘/test’.
Now, from a different device try the ‘curl’ command; something like this ‘curl http://192.168.1.251:12000/test’. The link used should have the same port as the one you use to access Node-red
You will have more chances for debugging.
It could be that the link is password protected, if in Node-Red you activated ‘httpNodeAuth’.


#11

Thanks for that, it was the Node-Red port number that I needed to put in there.

All working now :)


#12

I realize this is a bit old now but just throwing in my 2 cents. On the http input node I set it to POST and Accept File Uploads (this feature may have been added since the original post), I pass this into a function node with these two lines in it (very similar to how iura.alin) . . .

msg.payload = JSON.parse(msg.payload.payload);
return msg;

Also @groovygrovesy 's the url’s in node-red are relative to your base url, if you access node-red via http://localhost:21000/red and create a node called /plex then it’s full url is http://localhost:21000/red/plex I realize your issue is resolved but just in case it wasn’t clear to other people who find this post.

I would be very interested to know what people have come up with, I saw the suggestion on the Plex website about dimming the lights when you play a movie, sounds great, anyone got a IoT popcorn maker?


#13

No Iot popcorn maker for me, just light automation when I play a movie… :wink: But it’s seems that the webhook are very slow from plex. IThey are appearing sometimes many seconds after in node red…
Did you have the same problem?