Get Libraries
A Plex server can have many different libraries setup for various media. You can easily retrieve the information about all libraries that are available on a Plex server using this API command.
URL
GET http://{ip_address}:32400/library/sections/?X-Plex-Token={plex_token}
Parameters
Name | Description |
---|---|
ip_address | The IP address of the Plex Media server. |
plex_token | The Plex token. |
Return Status
HTTP Code | Description |
---|---|
200 | Success - The request was successful. |
401 | Unauthorized - The Plex token provided was not valid. |
Response
XML string value that lists the libraries that have been created on the Plex server. An example of the XML returned from the request is shown below:
<?xml version="1.0" encoding="UTF-8"?> <MediaContainer size="4" allowSync="0" identifier="com.plexapp.plugins.library" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1638961228" title1="Plex Library"> <Directory allowSync="1" art="/:/resources/movie-fanart.jpg" composite="/library/sections/2/composite/1640879224" filters="1" refreshing="0" thumb="/:/resources/movie.png" key="2" type="movie" title="Movies" agent="com.plexapp.agents.imdb" scanner="Plex Movie Scanner" language="en" uuid="493a64e7-b541-4667-b050-d702beebf2f6" updatedAt="1595491662" createdAt="1419621957" scannedAt="1640879224" content="1" directory="1" contentChangedAt="87188911" hidden="0"> <Location id="9" path="M:\Media\Movies" /> </Directory> <Directory allowSync="1" art="/:/resources/show-fanart.jpg" composite="/library/sections/4/composite/1640879304" filters="1" refreshing="0" thumb="/:/resources/show.png" key="4" type="show" title="TV Shows" agent="com.plexapp.agents.thetvdb" scanner="Plex Series Scanner" language="en" uuid="3bbbe6f7-628f-4983-ae5d-7c05779c4c28" updatedAt="1595493250" createdAt="1419642504" scannedAt="1640879304" content="1" directory="1" contentChangedAt="5613493" hidden="0"> <Location id="11" path="M:\Media\TV Shows" /> </Directory> <Directory allowSync="1" art="/:/resources/artist-fanart.jpg" composite="/library/sections/8/composite/1640879225" filters="1" refreshing="0" thumb="/:/resources/artist.png" key="8" type="artist" title="Music" agent="tv.plex.agents.music" scanner="Plex Music" language="en" uuid="b6031749-2969-4027-afee-64172b72b77d" updatedAt="1598392667" createdAt="1430573735" scannedAt="1640879225" content="1" directory="1" contentChangedAt="59913170" hidden="0"> <Location id="16" path="M:\Media\Music" /> </Directory> <Directory allowSync="1" art="/:/resources/photo-fanart.jpg" composite="/library/sections/1/composite/1640879303" filters="1" refreshing="0" thumb="/:/resources/photo.png" key="1" type="photo" title="Photos" agent="com.plexapp.agents.none" scanner="Plex Photo Scanner" language="xn" uuid="fc948ea9-3fad-45e2-99ef-b461b2d746d2" updatedAt="1600821139" createdAt="1419611117" scannedAt="1640879303" enableAutoPhotoTags="0" content="1" directory="1" contentChangedAt="115673999" hidden="0"> <Location id="10" path="M:\Media\Pictures" /> </Directory> </MediaContainer>
The XML returned provides a list of the libraries that are available on the Plex server. The root is the MediaContainer
element. This element contains a few attributes that provide overall information about the libraries on the server.
Attribute | Description |
---|---|
size | The number of libraries. |
allowSync | 1 - allow syncing content. 0 - don't allow syncing content. |
identifier | The type of item. |
mediaTagPrefix | Prefix for the media tag. |
mediaTagVersion | Media tag version. Note: This could be a date and time value. |
title1 | The title of the library. Note: This appears to be internally created, and can't be changed by the server owner. |
Within the MediaContainer
there are one or more Directory
child elements. Each Directory
element represents one library on the Plex server.
Attribute | Description |
---|---|
allowSync | 1 - allow the items in the to be synced. 0 - do not allow the items in the library to be synced. |
art | The background artwork used to represent the library. |
composite | The composite image associated with the library. |
filters | 1 - allow library filters. 0 - do no allow library filters. |
refreshing | 1 - the library is refreshing the metadata. 0 - the library is not refreshing the metadata. |
thumb | The thumbnail for the library. |
key | The relative URL of the information for the library. |
type | The type of item represented by this Directory element. |
title | The name of the library. |
agent | The agent used to set the metadata for the items in the library. |
scanner | The name of the scanner used to scan the library. |
language | The two-character language for the library. |
uuid | Unique identifier for the library. |
updatedAt | The date and time the library was updated in the library. |
createdAt | The date and time when the library was created. |
scannedAt | The date and time when the library was last scanned. |
content | Unknown. |
directory | Unknown. |
contentChangedAt | The date and time when the library content was last changed. |
hidden | 1 - the library is hidden. 0 - the library is not hidden. |
Within each of the Directory
elements can be one or more Location
child elements. These child elements specify the folder path of the files associated with each library.
The attributes of the Location
elements are:
Attribute | Description |
---|---|
id | Unique integer value used as the location identifier. |
path | The full path to the folder containing the files for the library. This value was specified when the library was added to the Plex server. |
Remarks
The Plex authentication token used to make the request will determine what libraries are returned.
If the token used is for a non-administrative user, then the libraries returned will only include the libraries the user can access. Libraries that the user cannot access will not be returned in the XML response.
When using a device Plex token, all libraries will be returned because libraries cannot be restricted for a device, only for users.
Examples
curl -X GET http://{ip_address}:32400/library/sections/?X-Plex-Token={plex_token}
import requests plex_url = http://{ip_address}:32400/library/sections/?X-Plex-Token={plex_token} response = requests.get(plex_url) print(response.text)
$response = Invoke-RestMethod 'http://{ip_address}:32400/library/sections/?X-Plex-Token={plex_token}' -Method 'GET' Write-Output $response
Script examples
Below are a list of post and articles that provide an example that use this API endpoint: