Plex Webhooks

Are you looking for Plex Support:

Please go here:

So my hub turned up today and have been starting work to port over Plex integration.. I've got most of the wrinkles ironed out apart from being able to receive status updates from plex..

My code is below and I receive the error "java.lang.IllegalArgumentException: Text must not be null or empty on line 358 (plexWebHookHandler)"

Pulling "params" out to logging only responds with access_token=xxxxxxxxxxx, so no payload appears to be being passed back like I would get in SmartThings..

Any ideas or help welcome..

import groovy.json.JsonSlurper
mappings {
  path("/pwh") 						{ action: [POST: "plexWebHookHandler"] }
}

def plexWebHookHandler(){

  def jsonSlurper = new JsonSlurper()
  def plexJSON = jsonSlurper.parseText(params)
  //do some stuff here
}
3 Likes

Just out of curiosity, what are you trying to do with Plex through Hubitat? I am a heavy Plex user being that we only have DSL available and use 4ktv's, but never thought about integrating it with Hubitat. I have a Synology DS918+ that I use as a whole house Plex media server.

Basically it creates a device for every Plex device and passes playstate and media type... you can then use it to control your lighting when a film starts etc.. and bring the lights back up when you pause or stop

2 Likes

params is a map of the query parameters, so it only contains values from the URL. If you are looking for the body of the request. try

log.debug request.JSON

or

log.debug request.XML

depending on the type of content you are sending to see what is in the body.

1 Like

Thanks I’ll give it a go later!

OK so I'm still not able to obtain the content for whatever reason..

request.JSON returns null, and just getting the content of request returns only:

[HOST:192.168.25.111]

Any ideas?

do you know what the headers are that the plex server is sending? I'm thinking the content-type is either not set or not set to something we recognize. I'm going to put in a ticket for us to add request.body to return the raw body from a request and you should be able to access it that way. unfortunately that means you need to wait until we can get that added unless you can configure the Content-Type header in the request.

Thanks, the only details I have are from the link below, like I say params works via ST just not in hubitat.

I’ll see if I can find a tool to act as an endpoint and see what’s in the raw data.. if something exists..

Thanks more than happy to wait as long as I can get it working at some point :slight_smile:

https://support.plex.tv/articles/115002267687-webhooks/

So here are the details of what's in the request..

From the header:
Content-Type: multipart/form-data; boundary=----------------------------5277aa8f4000

From the body:
Content-Type: application/json

Full details below:
https://requestbin.fullcontact.com/15cip361?inspect#u6xkge

Thanks for that information, it looks like we don't handle the multipart/form-data correctly. I'll put in a ticket for that as well.

1 Like

Great thanks, is there anyway for me to track it so I know once it’s complete?

Any update on this?

Thanks!

Hi @chuck.schwer do you have an ETA for the fix at all?

No ETA on the multpart parsing. But we did add the raw body to the request. Perhaps you can parse what you need that way? if you are on the latest build, you can use "request.body" to get it

Great cheers, I managed to trim the content then extract the required content.. I'm sure there is a more elegant way but it works..

Awesome! I'll install it tonight

1 Like

Just tested and it works great! Exactly what I was looking for!

Thank you!

Setup tips for others:

  • Enable OAuth for this app code in HE
  • Once initial setup is done, copy the webhooks address from this app to your Plex account Webhooks section.
1 Like

hmm not working for me :frowning:

You’re going to need to be a lot more descriptive if you need help? Firstly I assume you have Plex pass and you have configured Plex?

If so what are you getting in habitat logs? What is actually not working? Finding devices, or updating their status?

When I try to control play back nothing happens. I'll get some logs today.