# Node Red - Webhook

**URL:** <https://forums.plex.tv/t/node-red-webhook/178777>\
**Category:** Dev/API Corner\
**Tags:** other-dev\
**Created:** [February 5, 2017, 3:33pm UTC](https://forums.plex.tv/t/node-red-webhook/178777 "2017-02-05T15:33:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruben\_1](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@Ruben\_1](https://forums.plex.tv/u/Ruben_1)\
**Post date:** [February 5, 2017, 3:33pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/1 "2017-02-05T15:33:42Z")

</div>

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

![](https://global.discourse-cdn.com/plex/original/3X/9/d/9ddc1fdf5a19d048bff7ee8dc8e445cc7ba58179.png)

---

<div class="post-metadata">

**Author:** ![iura.alin](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@iura.alin](https://forums.plex.tv/u/iura.alin)\
**Post date:** [February 7, 2017, 6:49pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/2 "2017-02-07T18:49:30Z")

</div>

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](https://www.npmjs.com/package/node-red-contrib-http-multipart "https://npmjs.com/package/node-red-contrib-http-multipart")  
The response of this node can be afterwards processed like this:  
`json = JSON.parse(msg.payload.payload);`

---

<div class="post-metadata">

**Author:** ![Ruben\_1](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@Ruben\_1](https://forums.plex.tv/u/Ruben_1)\
**Post date:** [February 8, 2017, 3:59pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/3 "2017-02-08T15:59:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iura.alin](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@iura.alin](https://forums.plex.tv/u/iura.alin)\
**Post date:** [February 8, 2017, 4:04pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/4 "2017-02-08T16:04:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ruben\_1](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@Ruben\_1](https://forums.plex.tv/u/Ruben_1)\
**Post date:** [February 8, 2017, 4:19pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/5 "2017-02-08T16:19:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iura.alin](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@iura.alin](https://forums.plex.tv/u/iura.alin)\
**Post date:** [February 8, 2017, 4:41pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/6 "2017-02-08T16:41:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ruben\_1](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@Ruben\_1](https://forums.plex.tv/u/Ruben_1)\
**Post date:** [February 8, 2017, 5:01pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/7 "2017-02-08T17:01:59Z")

</div>

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

![](https://global.discourse-cdn.com/plex/original/3X/7/1/7171bce5e1f35a573084b6aba2a9859e9df632d4.png)

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;

---

<div class="post-metadata">

**Author:** ![iura.alin](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@iura.alin](https://forums.plex.tv/u/iura.alin)\
**Post date:** [February 8, 2017, 5:13pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/8 "2017-02-08T17:13:17Z")

</div>

This is it. Thanks

---

<div class="post-metadata">

**Author:** ![groovygrovesy](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@groovygrovesy](https://forums.plex.tv/u/groovygrovesy)\
**Post date:** [February 23, 2017, 10:20pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/9 "2017-02-23T22:20:33Z")

</div>

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)  
[http://192.168.1.251:12000/plex](http://192.168.1.251:12000/plex)  
[http://192.168.1.251/plex](http://192.168.1.251/plex)  
[http://192.168.1.251](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.

![](https://global.discourse-cdn.com/plex/original/3X/e/1/e105146680c3bc74f5c692fe00dfe6f107cc639a.jpg)

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

Thanks

---

<div class="post-metadata">

**Author:** ![iura.alin](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@iura.alin](https://forums.plex.tv/u/iura.alin)\
**Post date:** [February 24, 2017, 1:57pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/10 "2017-02-24T13:57:33Z")

</div>

Hi,

My implementation looks like below:

 ![](https://sea1.discourse-cdn.com/plex/uploads/default/original/3X/9/4/94566c4087f43971b986febb0cc62634271992aa.png)  
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](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’.

---

<div class="post-metadata">

**Author:** ![groovygrovesy](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@groovygrovesy](https://forums.plex.tv/u/groovygrovesy)\
**Post date:** [February 26, 2017, 3:52pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/11 "2017-02-26T15:52:53Z")

</div>

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

All working now 🙂

---

<div class="post-metadata">

**Author:** ![matt\_heys](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@matt\_heys](https://forums.plex.tv/u/matt_heys)\
**Post date:** [January 2, 2018, 2:48pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/12 "2018-01-02T14:48:58Z")

</div>

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](http://localhost:21000/red) and create a node called /plex then it’s full url is [http://localhost:21000/red/plex](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?

---

<div class="post-metadata">

**Author:** ![TribuMedia](https://avatars.discourse-cdn.com/v4/letter/t/87869e/32.png) [@TribuMedia](https://forums.plex.tv/u/TribuMedia)\
**Post date:** [February 9, 2018, 4:13pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/13 "2018-02-09T16:13:40Z")

</div>

No Iot popcorn maker for me, just light automation when I play a movie… 😉 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?

---

<div class="post-metadata">

**Author:** ![lykwan](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@lykwan](https://forums.plex.tv/u/lykwan)\
**Post date:** [October 10, 2018, 11:39am UTC](https://forums.plex.tv/t/node-red-webhook/178777/14 "2018-10-10T11:39:32Z")

</div>

Hi, I’m trying to following topic and emulate the steps. Any tutorial for me to follow step by step to create each node?

I’ve being able to setup this using but would like to use node red due to lack of support in homeassistant for node.js.

The idea is to get webhook from plex and trigger light automation.

```auto
var express = require('express')
  , request = require('request')
  , multer = require('multer');

var app = express();
var upload = multer({ dest: '/tmp/' });

app.post('/', upload.single('thumb'), function (req, res, next) {
  var payload = JSON.parse(req.body.payload);
  console.log('Got webhook for', payload.event);

 // USER INPUT: You only need the comment below once to get the UUID. Play a movie on the client you want to automate and run the script. You can comment out it when you got the UUID.
   console.log(payload.Player.uuid)

  // USER INPUT: Insert the UUID you got from the console instead of 'PLAYER-UUID'
 if (payload.Player.uuid == 'PLAYER-UUID' && payload.Metadata.type != 'track') {
	var options = {
      method: 'POST',
      json: true,
	  url: "http://192.168.1.2:8123/api/states/sensor.plex_sensor", 
	  headers: { Authorization: 'Bearer ' }
    };

    if (payload.event == 'media.play' || payload.event == 'media.resume') {
      console.log('Plex client playing');
      if (payload.Metadata.type == 'episode'){
      options.body = {'state':'Playing','attributes':{'series':payload.Metadata.grandparentTitle,'title':payload.Metadata.title,'season':payload.Metadata.parentIndex,'episode':payload.Metadata.index,'client':payload.Player.title, 'mediatype':payload.Metadata.type,'user':payload.Account.title}};
      }
      else{
      options.body = {'state':'Playing','attributes':{'title':payload.Metadata.title, 'client':payload.Player.title, 'mediatype':payload.Metadata.type, 'user':payload.Account.title }};
      }
      request(options);
    } else if (payload.event == 'media.pause') {
      console.log('Plex client paused');
      options.body = {'state':'Paused'};
      request(options);
    } else if (payload.event == 'media.stop'){
      console.log('Plex client stopped');
      options.body = {'state':'Stopped'};
      request(options);
    }
  }

  res.sendStatus(200);
});
// USER INPUT: Choose the port of your liking.
app.listen(12000);

```

---

<div class="post-metadata">

**Author:** ![oliver9523](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/oliver9523/32/14409_2.png) [@oliver9523](https://forums.plex.tv/u/oliver9523)\
**Post date:** [October 15, 2018, 8:51pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/15 "2018-10-15T20:51:07Z")

</div>

I’m still seeing slow webhook posts from plex too, did this ever get solved?

---

<div class="post-metadata">

**Author:** ![TribuMedia](https://avatars.discourse-cdn.com/v4/letter/t/87869e/32.png) [@TribuMedia](https://forums.plex.tv/u/TribuMedia)\
**Post date:** [October 16, 2018, 8:35pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/16 "2018-10-16T20:35:27Z")

</div>

No I didn’t get solved, I dropped this solution which is unstable

---

<div class="post-metadata">

**Author:** ![McNutty195](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@McNutty195](https://forums.plex.tv/u/McNutty195)\
**Post date:** [March 2, 2019, 8:50pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/17 "2019-03-02T20:50:09Z")

</div>

Hi, don’t mean to revive an old ish thread, but I have been trying to get an http in node in nodered to accept a local webhook from plex, but I can’t figure out how to get it to work.

I’ve got Plex posting webhooks to 192.168.1.33:1880/Plex

That ip address being the IP address for my home assistant virtual machine which has the nodered add-on running. I’ve got an http in node in post mode with the accept file downloads checked, but nothing is coming in. I have it set to watch /plex.

Any ideas what’s wrong?

---

<div class="post-metadata">

**Author:** ![doh](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/doh/32/4401_2.png) [@doh](https://forums.plex.tv/u/doh)\
**Post date:** [June 15, 2019, 8:01pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/18 "2019-06-15T20:01:50Z")

</div>

I’ve Just been playing with this and managed to get it to work - here’s a test flow you can import and try…

`[{"id":"17b0ecc7.aaa9e3","type":"tab","label":"Plex test","disabled":false,"info":""},{"id":"3cab80ec.d92ae","type":"debug","z":"17b0ecc7.aaa9e3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":510,"y":260,"wires":[]},{"id":"d159aee8.6e503","type":"http in","z":"17b0ecc7.aaa9e3","name":"Plex WebHook","url":"/plex","method":"post","upload":true,"swaggerDoc":"","x":210,"y":260,"wires":[["94b7b65f.227a08"]]},{"id":"94b7b65f.227a08","type":"function","z":"17b0ecc7.aaa9e3","name":"Parse","func":"msg.payload = JSON.parse(msg.payload.payload);\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":420,"wires":[["3cab80ec.d92ae","807a187d.5d2478","4c8ceb11.1a9f84","c7907c52.36c1c"]]},{"id":"807a187d.5d2478","type":"debug","z":"17b0ecc7.aaa9e3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.event","targetType":"msg","x":650,"y":340,"wires":[]},{"id":"4c8ceb11.1a9f84","type":"debug","z":"17b0ecc7.aaa9e3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.Account.title","targetType":"msg","x":670,"y":380,"wires":[]},{"id":"c7907c52.36c1c","type":"switch","z":"17b0ecc7.aaa9e3","name":"","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"media.play","vt":"str"},{"t":"eq","v":"media.resume","vt":"str"},{"t":"eq","v":"media.pause","vt":"str"},{"t":"eq","v":"media.stop","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":610,"y":480,"wires":[[],[],[],[]]}]`

---

<div class="post-metadata">

**Author:** ![McNutty195](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@McNutty195](https://forums.plex.tv/u/McNutty195)\
**Post date:** [June 17, 2019, 4:47pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/19 "2019-06-17T16:47:04Z")

</div>

Thanks for the suggestion and reply. After a while I came to the conclusion that I would have to open the port for plex on my router to get the webhooks to work. I instead decided to just move to an “addon” for node red that gets the information directly.

I appreciate you posting though!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [January 8, 2020, 8:02pm UTC](https://forums.plex.tv/t/node-red-webhook/178777/20 "2020-01-08T20:02:05Z")

</div>


