Hello Plex Community
i have struggled for two evenings with flask to get the webhooks working. Maybe some one can also use this as a starting point.
I have used:
- Python 3 as venv and flask
My Webhook in plex looks like that
http://192.168.188.26:5000/plex
Python Flask Script
from flask import Flask, request
import json
app = Flask(__name__)
@app.route('/plex', methods=['POST'])
def listener():
data = request.form.getlist('payload')
m = data[0]
n = json.dumps(m)
o = json.loads(n)
p = json.loads(o)
print("event : "+p['event'])
print("user : "+str(p['user']))
print("owner : "+str(p['owner']))
print("Account title : "+p["Account"]['title'])
print("Server title : "+p["Server"]["title"])
print("Player title : "+p["Player"]["title"])
print("Metadata librarySectionTitle : "+p["Metadata"]["librarySectionTitle"])
return "Ack"
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0')
The output looks like that
* Serving Flask app "plex" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 125-568-481
event : media.resume
user : True
owner : True
Account title : th9luckyone
Server title : Berlin
Player title : Safari
Metadata librarySectionTitle : TV Shows
192.168.188.24 - - [02/Feb/2021 19:42:22] "POST /plex HTTP/1.0" 200 -
As shown in the output. This is not for production. Only use this for testing.
Follow the deployment guide on flask. Also use TLS if you are not just in your own network