{"id":313,"date":"2025-12-18T15:15:38","date_gmt":"2025-12-18T15:15:38","guid":{"rendered":"https:\/\/niklouch.com\/blog\/?p=313"},"modified":"2025-12-18T15:36:39","modified_gmt":"2025-12-18T15:36:39","slug":"plex-api-quickstart","status":"publish","type":"post","link":"https:\/\/niklouch.com\/blog\/plex-api-quickstart\/","title":{"rendered":"Plex API Quickstart"},"content":{"rendered":"\n<p>I&#8217;ve been running <a href=\"https:\/\/www.plex.tv\/\" data-type=\"link\" data-id=\"https:\/\/www.plex.tv\/\" target=\"_blank\" rel=\"noreferrer noopener\">Plex <\/a>for a few years now, and while I&#8217;m fully aware that there are potentially <a href=\"https:\/\/jellyfin.org\/\" data-type=\"link\" data-id=\"https:\/\/jellyfin.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">more preferred server applications<\/a> 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 &#8211; and does it well, with a clean interface, native apps and decent transcoding.  And here&#8217;s where the inner geek gets involved &#8211; it has a pretty decent API also!<\/p>\n\n\n\n<p>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&#8217;s available, recent uploads &#8211; all very much <a href=\"https:\/\/www.plexopedia.com\/plex-media-server\/api\/\" data-type=\"link\" data-id=\"https:\/\/www.plexopedia.com\/plex-media-server\/api\/\" target=\"_blank\" rel=\"noreferrer noopener\">documented by people more educated on the subject than I am<\/a> and all absolutely informing the lessons I learned from <a href=\"https:\/\/chatgpt.com\/\" data-type=\"link\" data-id=\"https:\/\/chatgpt.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">ChatGPT<\/a>.  So I&#8217;m not going to pretend that this is any sort of &#8220;<em>How To<\/em>&#8220;, but rather &#8220;<em>Here&#8217;s how I&#8217;m doing it<\/em>&#8220;.<\/p>\n\n\n\n<p>Querying your local server is really easy, and authentication relies only upon an access token &#8211; however, to get that access token, you need to query the cloud API &#8211; which annoyingly relies upon email and password &#8211; ugh.  So, what I&#8217;ve done is the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check for a cached local server access token &#8211; which will not exist upon first run<\/li>\n\n\n\n<li>Prompt for credentials to access the cloud server<\/li>\n\n\n\n<li>Query the cloud server, to get local server details<\/li>\n\n\n\n<li>Cache the local server access token<\/li>\n\n\n\n<li>Run the query needed against the local server, using the local server access token<\/li>\n<\/ul>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>I threw this together in <a href=\"https:\/\/learn.microsoft.com\/en-us\/powershell\/\" data-type=\"link\" data-id=\"https:\/\/learn.microsoft.com\/en-us\/powershell\/\" target=\"_blank\" rel=\"noreferrer noopener\">PowerShell<\/a>, with sufficient documentation for a novice to start tinkering, so you can grab it from <a href=\"https:\/\/github.com\/NLouch\/PlexScripts\/blob\/main\/GetRecentMovies.ps1\" data-type=\"link\" data-id=\"https:\/\/github.com\/NLouch\/PlexScripts\/blob\/main\/GetRecentMovies.ps1\" target=\"_blank\" rel=\"noreferrer noopener\">my Github&#8230;<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Having run Plex locally for a few years, I&#8217;m starting to play with it&#8217;s API.  This article details my first steps &#8211; including credentials, authentication, and access&#8230;<\/p>\n","protected":false},"author":1,"featured_media":316,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,17],"tags":[9,42,12,43,44],"class_list":["post-313","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","category-tech","tag-api","tag-code","tag-github","tag-plex","tag-powershell"],"_links":{"self":[{"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/posts\/313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/comments?post=313"}],"version-history":[{"count":1,"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/posts\/313\/revisions"}],"predecessor-version":[{"id":315,"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/posts\/313\/revisions\/315"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/media\/316"}],"wp:attachment":[{"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/media?parent=313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/categories?post=313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/niklouch.com\/blog\/wp-json\/wp\/v2\/tags?post=313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}