Add a Library
Before adding media to a Plex server, a library for the media type must first be created. The API command explained on this page will add a single library to a Plex server.
Since all media libraries are added in the same manner, this command can be complex as all options for each library type must be handled.
URL
POST http://{ip_address}:32400/library/sections?name={name}&type={type}&agent={agent}&scanner={scanner}&language={language}&location={media_location}&{preferences}&X-Plex-Token={plex_token}
Parameters
Name | Description |
---|---|
ip_address | The IP address of the Plex Media server. |
plex_token | The Plex token. |
name | The name of the new library. |
type | The type of library to be added See Library Types. |
agent | The agent that will be associated with the library See Agents. |
scanner | The scanner that will be associated with the library See Scanners. |
language | The language of the library, See Library Languages. |
media_location | The location of the media files. This parameter can be specified multiple times if more than one location will be used for the library media. |
preferences | Optional. Additional settings for the library See Preferences. |
Return Status
HTTP Code | Description |
---|---|
201 | Created - The request was successful. |
400 | Bad Request. A parameter is invalid or not provided. The response contains the error messages. |
401 | Unauthorized - The Plex token provided was not valid. |
Response
When a library is successfully created, an XML string value that contains information about the new library is returned:
<?xml version="1.0" encoding="UTF-8"?> <MediaContainer size="1"> <Directory art="/:/resources/movie-fanart.jpg" composite="/library/sections/20/composite/1700011778" thumb="/:/resources/movie.png" key="20" type="movie" title="My Movies" agent="tv.plex.agents.movie" scanner="Plex Movie" language="en-US" uuid="23355a75-a85b-4420-8ed9-0a781010c8ad" updatedAt="1700011778" createdAt="1700011778" content="1" directory="1" contentChangedAt="0" hidden="0"> <Location id="23" path="M:\Movies" /> </Directory> </MediaContainer>
If the library could not be created, string values are returned that explain the reasons why the library could not be created.
The XML returned contains information about the new library. The root is the MediaContainer
element. This element contains only a single size
attribute that indicates one Directory
element was returned.
Attribute | Description |
---|---|
size | The number of libraries. |
Within the MediaContainer
there is one Directory
element. The Directory
element will contain information about the new library.
Attribute | Description |
---|---|
art | The background artwork used to represent the item. |
composite | The composite image associated with the item. |
thumb | The thumbnail for the item. |
key | The relative URL of the information for the item. |
type | The type of item represented by this Directory element. |
title | The name of the item. |
agent | The agent used to set the metadata for the items in the library. |
scanner | The name of the scanner used to scan the item. |
Within the Directory
element there is one Location
child element that provides information about the media files location for the library.
Attribute | Description |
---|---|
id | The unique identifier for the item. |
path | The full path of the item. |
Remarks
Library Types
There are four types of libraries that can be added to Plex. When using the Web app to add a library, there are five types, but two use the same type when using the API.
The types are as follows:
Value | Library Type |
---|---|
movie | Movies, Other videos |
show | TV shows |
artist | Music |
photo | Photos |
The Value in the table above is what you would use in the API request to the Plex server.
Agents
Agents take information from the library scanner and then retrieve the metadata for each item in the library. A library can have one associated agent. One agent must be specified when adding a library, but can be changed later.
The tables in the next sections list the valid agents. The agents marked with "Default" are the agents selected when adding a library using the Plex Web app. Use the value in the "Value" column in the API request.
The valid agents for each library type are as follows:
Movies and other videos
Value | Name |
---|---|
tv.plex.agents.movie | Plex Movie (Default: Movies) |
com.plexapp.agents.none | Personal media (Default: Other videos) |
com.plexapp.agents.imdb | Plex Movie (Legacy) |
com.plexapp.agents.themoviedb | The Movie Database |
TV shows
Value | Name |
---|---|
tv.plex.agents.series | Plex TV Series (Default) |
com.plexapp.agents.none | Personal Media Shows |
com.plexapp.agents.thetvdb | TheTVDB |
com.plexapp.agents.themoviedb | The Movie Database |
Music
Value | Name |
---|---|
tv.plex.agents.music | Plex Music (Default) |
com.plexapp.agents.none | Personal Media Artists |
com.plexapp.agents.lastfm | Last.fm |
Scanners
Library scanners are used to scan the media in the folders associated with the library and then pass that information to the agent.
The valid scanners for each media type are listed in the sections below. The ones marked with "Default" are the default scanners used when adding a library from the Plex Web app. You only include the scanner name in the request.
Movies and other videos
- Plex Movie (Default: Movies)
- Plex Movie Scanner
- Plex Video Files Scanner
- Plex Video Files Scanner (Default: Other videos)
TV shows
- Plex TV Series (Default)
- lex Series Scanner
Music
- Plex Music (Default)
- Plex Music Scanner
Library languages
All libraries require a language to be specified. The supported languages for a library are dependent on the type. For the "Other Videos" library, the only option available is "None", which means no true language can be selected.
The next few sections list all the available language options for each library type.
Movies and TV shows
Code | Language |
---|---|
ar-SA | Arabic (Saudi Arabia) |
bg-BG | Bulgarian |
ca-ES | Catalan |
zh-CN | Chinese |
zh-HK | Chinese (Hong Kong) |
zh-TW | Chinese (Taiwan) |
hr-HR | Croatian |
cs-CZ | Czech |
da-DK | Danish |
nl-NL | Dutch |
en-US | English |
en-AU | English (Australia) |
en-CA | English (Canada) |
en-GB | English (UK) |
et-EE | Estonian |
fi-FI | Finnish |
fr-FR | French |
fr-CA | French (Canada) |
de-DE | German |
el-GR | Greek |
he-IL | Hebrew |
hi-IN | Hindi |
hu-HU | Hungarian |
id-ID | Indonesian |
it-IT | Italian |
ja-JP | Japanese |
ko-KR | Korean |
lv-LV | Latvian |
lt-LT | Lithuanian |
nb-NO | Norwegian Bokmål |
fa-IR | Persian |
pl-PL | Polish |
pt-BR | Portuguese |
pt-PT | Portuguese (Portugal) |
ro-RO | Romanian |
ru-RU | Russian |
sk-SK | Slovak |
es-ES | Spanish |
es-MX | Spanish (Mexico) |
sv-SE | Swedish |
th-TH | Thai |
tr-TR | Turkish |
uk-UA | Ukrainian |
vi-VN | Vietnamese |
Music and photos
Code | Language |
---|---|
id | Bahasa Indonesia |
da | Dansk |
de | Deutsch |
en | English |
es | Español |
fr | Français |
it | Italiano |
hu | Magyar |
nl | Nederlands |
nn | Norsk nynorsk |
pl | Polski |
pt | Português |
fi | Suomeksi |
sv | Svenska |
vi | Tiếng Việt |
tr | Türkçe |
xx | Unknown |
hr | hrvatski |
ro | română |
sk | slovenčina |
cs | čeština |
el | Ελληνικά |
bg | български език |
ru | русский язык |
sr | српски језик |
ar | العربية |
th | ไทย |
zh | 中文 |
ja | 日本語 |
ko | 한국어 |
Photos include all languages in the above table and the option of "None" in the next table.
Photos and other videos
Code | Language |
---|---|
xn | None |
Preferences
When adding a library using the Plex Web app there is an Advanced section that provides different options for each library type.
When using the API to add a library, these options are provided in the request in the form prefs[name]
. Each preference option would be a separate parameter in the request.
There are default values for each preference and if you wish to use the default value then you wouldn't specify the preference in the request. This means that all preferences are optional if you just wish to use the default values.
Each library will have its own set of preferences, and some preferences can be set for different library types. The preferences are listed below.
Visibility
- Name: hidden
- Parameter Values:
0 - (Default) Include in home screen and global search
1 - Exclude from home screen
2 - Exclude from home screen and global search - Library Type: Moves, TV Shows, Music, Photos
Enable Cinema Trailers
- Name: enableCinemaTrailers
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Moves, Other Videos
Use original titles
- Name: originalTitles
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies, TV Shows
Prefer artwork based on library language
- Name: localizedArtwork
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Movies, TV Shows
Use local assets
- Name: useLocalAssets
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Movies, TV Shows
Prefer local metadata
- Name: respectTags
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies, TV Shows, Music
Find extras
- Name: useExternalExtras
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Movies, TV Shows
Only show trailers
- Name: skipNonTrailerExtras
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies, TV Shows
Allow red band trailers
- Name: useRedbandTrailers
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies, TV Shows
Localized subtitles
- Name: includeExtrasWithLocalizedSubtitles
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies, TV Shows
Include adult content
- Name: includeAdultContent
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies, TV Shows
Minimum automatic collection size
- Name: autoCollectionThreshold
- Value:
0 - (Default) Disabled
1 - 1
2 - 2
3 - 3
4 - 4 - Library Type: Movies
Ratings Source
- Name: ratingsSource
- Value:
rottentomatoes - (Default) Rotten Tomatoes
imdb - IMDb
themoviedb - The Movie Database - Library Type: Movies
Enable video preview thumbnails
- Name: enableBIFGeneration
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Movies, TV Shows, Photos, Other Videos
Collections
- Name: collectionMode
- Value:
0 - Disabled
1 - Hide items which are in collections
2 - (Default) Show collections and their items - Library Type: Movies, TV Shows, Other Videos
Episode sorting
- Name: episodeSort
- Value:
-1 - (Default) Library default
0 - Oldest first
1 - Newest first - Library Type: TV Shows
Episode ordering
- Name: showOrdering
- Value:
tmdbAiring - (Default) The Movie Database
aired - TheTVDB - Library Type: TV Shows
Use season titles
- Name: useSeasonTitles
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: TV Shows
Seasons
- Name: flattenSeasons
- Value:
0 - (Default) Show
1 - Hide
2 - Hide for single-season series - Library Type: TV Shows
Album sorting
- Name: albumSort
- Value:
-1 - (Default) Library default
0 - Oldest first
1 - Newest first
2 - By name - Library Type: Music
Store track progress
- Name: enableTrackOffsets
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Music
Include related content from shared libraries
- Name: augmentWithSharedContent
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Music
Artist Bios
- Name: artistBios
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Music
Album Reviews and Critic Ratings
- Name: albumReviews
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Music
Popular Tracks
- Name: popularTracks
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Music
Genres
- Name: genres
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Music
Album Artist
- Name: albumPosters
- Value:
1 - (Default) Both Plex Music and Local Files
2 - Plex Music Only
3 - Local Files Only - Library Type: Music
Plex Movie (Legacy) Preferences
If you select Plex Movie (Legacy) as the movie agent, there are some additional preferences that can be set for that agent.
The preferences for this agent are listed below.
Localized titles
- Name: title
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies
Find trailers and extras automatically (Plex Pass required)
- Name: extras
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Movies
Skip extras which aren't trailers
- Name: only_trailers
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies
Use red band (restricted audiences) trailers when available
- Name: redband
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies
To set the above preferences, a second API request will need to be sent to the Plex server. This request is as follows:
GET http://{ip_address}:32400/:/plugins/com.plexapp.agents.imdb/prefs/set?title=[Value]&extras=[Value]&only_trailers=[Value]&redband=[Value]&X-Plex-Token={plex_token}
The Movie Database Settings
There are additional preferences that can be specified when using The Movie Database agent. These setting are listed below.
Use collection info from The Movie Database
- Name: collections
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies
Prefer artwork based on library language
- Name: localart
- Value:
0 - Unchecked
1 - (Default) Checked - Library Type: Movies
Include adult content
- Name: adult
- Value:
0 - (Default) Unchecked
1 - Checked - Library Type: Movies
Country
- Name: country
- Value:
A value from the below table. - Library Type: Movies
Value | Language |
---|---|
0 | (Blank) |
1 | Argentina |
2 | Australia |
3 | Austria |
4 | Belgium |
5 | Belize |
6 | Bolivia |
7 | Brazil |
8 | Canada |
9 | Chile |
10 | Colombia |
11 | Costa Rica |
12 | Czech Republic |
13 | Denmark |
14 | Dominican Republic |
15 | Ecuador |
16 | El Salvador |
17 | France |
18 | Germany |
19 | Guatemala |
20 | Honduras |
21 | Hong Kong SAR |
22 | Ireland |
23 | Italy |
24 | Jamaica |
25 | Korea |
26 | Liechtenstein |
27 | Luxembourg |
28 | Mexico |
29 | Netherlands |
30 | New Zealand |
31 | Nicaragua |
32 | Panama |
33 | Paraguay |
34 | Peru |
35 | Portugal |
36 | Peoples Republic of China |
37 | Puerto Rico |
38 | Russia |
39 | Singapore |
40 | South Africa |
41 | Spain |
42 | Sweden |
43 | Switzerland |
44 | Taiwan |
45 | Trinidad |
46 | United Kingdom |
47 | United States |
48 | Uruguay |
49 | Venezuela |
To set The Movie Database preferences, a second API request will need to be sent to the Plex server. This request is as follows:
GET http://{ip_address}:32400/:/plugins/com.plexapp.agents.themoviedb/prefs/set?collections=[Value]&localart=[Value]&adult=[Value]&country=[Value]&X-Plex-Token={plex_token}
Examples
curl -X POST http://{ip_address}:32400/library/sections?name={name}&type={type}&agent={agent}&scanner={scanner}&language={language}&location={media_location}&{preferences}&X-Plex-Token={plex_token}
import requests plex_url = http://{ip_address}:32400/library/sections?name={name}&type={type}&agent={agent}&scanner={scanner}&language={language}&location={media_location}&{preferences}&X-Plex-Token={plex_token} response = requests.post(plex_url) print(response.text)
$response = Invoke-RestMethod 'http://{ip_address}:32400/library/sections?name={name}&type={type}&agent={agent}&scanner={scanner}&language={language}&location={media_location}&{preferences}&X-Plex-Token={plex_token}' -Method 'POST' Write-Output $response