Add items to a Collection using Plex API

I’m writing an c# application to create and manage Collections using the Plex API. I’ve managed to iterate and list my Plex library and Collections, but creating new Collections and adding items to existing collections give me great difficulties.

I managed to create a new Collection in an existing library, but it remains empty. The referenced item is not added to the collection.

url: https://{server url}:32400/library/collections?type=1&title={Title}&uri=server://{serverID}/com.plexapp.plugins.library/library/metadata/{movie ratingKey}&X-Plex-Token={PlexToken}&sectionId={Library ratingKey}

(Via code & directly via PostMan, using the Post command)

When I try to add an item to the newly created collection using the url below, I keep getting a Bad Request response.

url: https://{server ip}:32400/library/collections/{ratingKey of collection}/items?uri=server://{serverID}/com.plexapp.plugins.library/library/metadata/{ratingKey of movie}

Via Postman and code. PostMan, PUT and added the x-plex-token to the header. (If I leave that out I get a Unauthorized response) Also tried via POST and adding the token to the url, but that returns a not found response.

What am I overlooking? :slight_smile:

Simply add the medias like this, and it’s a PUT

<PMS_URL_WITH_PORTNUMBER>/library/sections/<LIBRARY_KEY>/all?type=1&id=<COMMA_SEPERATED_MEDIA_KEYS>&includeExternalMedia=1&collection.locked=1&collection[0].tag.tag=<COLLECTION_NAME>&X-Plex-Client-Identifier=<UNIQUE_CLIENTID_FOR_YOUR_APP>&X-Plex-Token=<YOUR_TOKEN>

Above url needs to be URL Encoded before you send the request, and yes, the token can be put into the header (preferred)

And in above, type=1 means movies
Ref: https://developer.plex.tv/pms/#section/API-Info/Types


Another way is to add items to an existing collection like see here:
https://developer.plex.tv/pms/#tag/Library-Collections/operation/libraryCollectionCollectionPutItems

Apologies, this was clearly an issue that existed between keyboard & chair…

If somebody comes across this topic with similar issues, the urls I use are 100% correct. I don’t know how, but I somehow got the serverID wrong. If you go to you Plex web interface: https://app.plex.tv/desktop/#!/media/{this long number is your serverID}/

@dane22 Thanks! Didn’t see an example with the collection[0]tag.tag added to it, will look into that one as well. Adding items indeed only work with PUT, POST returns 404 not found.

I turned on the debugger in the webclient, and added a few movies to a new collection named testColand saw that :slight_smile: