Plex API Quickstart

Plex Code

I’ve been running Plex for a few years now, and while I’m fully aware that there are potentially more preferred server applications available (due to technology stack, cost, etc), I still consider Plex my go-to, especially as I share with tech-illiterate friends/family. It basically hosts my photos, family videos, DVD rips – and does it well, with a clean interface, native apps and decent transcoding. And here’s where the inner geek gets involved – it has a pretty decent API also!

A few friends have recently setup similar systems and we got onto the discussion of using the API to query your local server to get stats, details of who is watching what, what’s available, recent uploads – all very much documented by people more educated on the subject than I am and all absolutely informing the lessons I learned from ChatGPT. So I’m not going to pretend that this is any sort of “How To“, but rather “Here’s how I’m doing it“.

Querying your local server is really easy, and authentication relies only upon an access token – however, to get that access token, you need to query the cloud API – which annoyingly relies upon email and password – ugh. So, what I’ve done is the following:

  • Check for a cached local server access token – which will not exist upon first run
  • Prompt for credentials to access the cloud server
  • Query the cloud server, to get local server details
  • Cache the local server access token
  • Run the query needed against the local server, using the local server access token

Again, this may or may not be a best practice, but it works for me. Running the script the first time manually allows the prompt for credentials, and thereafter it will not need to do so again.

I threw this together in PowerShell, with sufficient documentation for a novice to start tinkering, so you can grab it from my Github…

Leave a Reply

Your email address will not be published. Required fields are marked *