Plex Webhook: Assign JSON payload events to variables

Hello. I’m having some trouble parsing a JSON payload and assigning variables to specific events. I followed the instructions here, but I’m stuck on how to actually retrieve the JSON data and assign it to variables.

I’m using Plex to send a webhook to the rule I’ve created in SharpTools.

I’ve set up a HTTP trigger and copied the URL into the webhook settings in Plex.

I have an action set up to assign a variable to a specific payload called ‘event’.
Set variable $event value using $context.event.params.event value

Plex seems to successfully trigger the rule according to the log, but I keep getting this error…

12:41:24 PM
Triggered by http event: API Key 353dddxxx-xxxx-xxxx-xxxx-xxxxxxce191e

12:41:24 PM
Set variable value: $event = undefined

The data is supposed to be ‘media.stop’ or ‘media.play’.

Any ideas what I’m doing wrong?

Can you PM me the Rule ID so I can take a closer look at the payload that’s being received?

The format $context.event.params.event would imply that the source is sending over a payload with an object that has an event property, is that right?

{
  "event": 
    { 
        "foo": "bar" 
        ...
    }
}

or

{
  "event": "XXX",
  "foo": "bar"
  ...
}

That’s correct. There is a payload called ‘event’ that is supposed to be sending something like ‘media.stop’ or media.play’.

I will PM the Rule ID.

Forgive me I’m new here. How do I PM a message? I can’t seem to find it.

Normally you would tap my profile icon and then see a ‘Message’ button. As a new community member, you may not see that feature right away.

I was able to create a webhook using my Plex account, so I’m taking a look at it now. :slight_smile:

1 Like

It looks like the Plex Webhook implementation is kind of quirky. Instead of sending the webhook over as a traditional webhook with JSON as the body, they’re using a special form encoding which is usually reserved for files and embedding the JSON within that.

Anyway, it’s an odd format, but we’ll take a look at extending the Rule HTTP Trigger to support it in a future update.

1 Like

Ok thank you. Glad it wasn’t just me.

We pushed an update to support the weird Plex format. :slight_smile:

Wow! You’ve made my day.

It is working great now!

1 Like

How did you get this working? I have a rule set up with a webhook and in the logs I can see the data is coming through to sharp tools but I have not idea how to use this data to trigger anything.

What I want to do is use the event media.play to trigger a scene in Smartthings

You can assign any parameters you want to context variables. In this case you want the “event” parameter.

context

contextevent

1 Like

Perfect, thank you very much