If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

Node Red - Webhook

RubenRuben Posts: 23Members, Plex Pass Plex Pass

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.?

Best Answer

  • RubenRuben Posts: 23Members, Plex Pass Plex Pass
    edited February 2017 Accepted Answer

    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("\n--");
    json = json.substr(0, endPosition);

    msg.payload = json;

    return msg;

Answers

  • iura.aliniura.alin Posts: 12Members, Plex Pass Plex Pass

    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);

  • RubenRuben Posts: 23Members, Plex Pass Plex Pass

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

  • iura.aliniura.alin Posts: 12Members, Plex Pass Plex Pass

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

  • RubenRuben Posts: 23Members, Plex Pass Plex Pass

    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.

  • iura.aliniura.alin Posts: 12Members, Plex Pass Plex Pass

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

  • RubenRuben Posts: 23Members, Plex Pass Plex Pass
    edited February 2017 Accepted Answer

    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("\n--");
    json = json.substr(0, endPosition);

    msg.payload = json;

    return msg;

  • iura.aliniura.alin Posts: 12Members, Plex Pass Plex Pass

    This is it. Thanks

  • groovygrovesygroovygrovesy Posts: 2Members, Plex Pass Plex Pass

    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

  • iura.aliniura.alin Posts: 12Members, Plex Pass Plex Pass
    edited February 2017

    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'.

  • groovygrovesygroovygrovesy Posts: 2Members, Plex Pass Plex Pass

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

    All working now :)

  • matt_heysmatt_heys Posts: 20Members, Plex Pass, TunerTester Plex Pass

    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?

Sign In or Register to comment.