However I cannot figure out how to get the add to playlist functionality to work.
I have spent several days (not all day) trying to resolve this problem.
I can delete items from a playlist and do almost anything else that I have tried but for some odd reason I cannot get the add to playlist URL to work.
The part of the API where the {library_id} might be part of the problem although I have read and re-read the bottom part of the page where it says to hover over the item in question and the “Library Key” parameter will be displayed.
I am not sure if this is the same thing but I have tried numerous variations on the API call using curl also and keep getting a 404 error.
Curiously this is also the only part of the API where it does not reference get this key valu from some other API call.
Please note I am on the local server when trying to accomplish this task.
I can build a window in Java that contains the movie name and other parameters including check boxes with a list of the playlists the movie is included or excluded from.
I can remove the movie from a playlist but cannot add it to one by checking or unchecking the box.
And yes the machine ID I am using agrees with everything I see in the Plex Web app and the API call.
If you look in the debugger of a browser while using the webclient to add a track to an existing music playlist, you’ll notice that the method is a PUT so are you sure you are using that, and not a GET
One note here is that trying to get the InputStream stream = … causes an exception but does not return a meaningful indication of what went wrong - e.getMessage() →
And Nit, but since you are writing the url with the token to your log, I suggest adding the token to the header instead of the url, to avoid logging the token!
The suggestion to use connection.setRequestProperty was awesome - but I don’t know if that helped solve the problem but it did make things easier for me.
So the & should be a ? needs to be corrected there.
Also I think then next big thing that needs to be corrected on that page is the API call says:
PUT http://{ip_address}:32400/playlists/{playlist_id}&uri=…
needs to be:
PUT http://{ip_address}:32400/playlists/{playlist_id}/items?uri=…
Note the addition of /items before the [&/?]uri=
Again thanks for your assistance!
I think I still need to make sure I get rid of the hard-coded Library_Id/Library_Key parameter and it would be great if that page could reflect how to find that directly through the API instead of the suggestion to hover in the browser.
But I can sleep easier tonight and thanks again for your assistance!
Using a GET with above will return a list of playlists with their keys
Also note that above call use paging, so if you have more than 50 playlists, you must run the call again, but this time set X-Plex-Container-Start to 51
I have returned to the dynamic Library_Key and that is working as expected.
Just a note - my application is only looking at what is playing at the current time. I want to be able to adjust what playlist the currently playing item belongs to, I use Plex mostly on ROKU devices and don’t want to have to remember or write down items that I want to add or remove from a playlist when I cannot/(don’t want to) use a computer to make adjustments.
One note is that I was retrieving the parameter for the ViewCount and that was causing an exception on new items that had not been completely viewed yet. But that has been handled now also.
I don’t really have many playlists so the size/(playlist length) will likely not be a problem/consideration. But I will keep that in mind.
My goal at the moment is to move the Java application into an Android app that I can use while laying in bed and adjust playlist items.
But who knows. I might add more features that I desire later.
Again thanks for your assistance!
One other note. I found the site that I used for development after using direct access to the database but was having difficulty getting the joins right.
PSS? - I also found the site that you referenced later but found it hard to interpret the documentation. Exactly what I needed to send to the server etc… But I’m an old guy and semi-retired and just kinda doing this as a hobby now so might not be as sharp as I once was…
This might be a use case where web hooks could be beneficial. You can be notified of certain events which occur on the server (playback start/stop, for example). The event payload includes a lot of (potentially) useful information, including paths to the artwork for the item being acted upon.