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

NameDescription
ip_addressThe IP address of the Plex Media server.
plex_tokenThe Plex token.
nameThe name of the new library.
typeThe type of library to be added See Library Types.
agentThe agent that will be associated with the library See Agents.
scannerThe scanner that will be associated with the library See Scanners.
languageThe language of the library, See Library Languages.
media_locationThe location of the media files. This parameter can be specified multiple times if more than one location will be used for the library media.
preferencesOptional. Additional settings for the library See Preferences.

Return Status

HTTP CodeDescription
201Created - The request was successful.
400Bad Request. A parameter is invalid or not provided. The response contains the error messages.
401Unauthorized - 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.

MediaContainer Attributes
AttributeDescription
sizeThe number of libraries.

Within the MediaContainer there is one Directory element. The Directory element will contain information about the new library.

Directory Attributes
AttributeDescription
artThe background artwork used to represent the item.
compositeThe composite image associated with the item.
thumbThe thumbnail for the item.
keyThe relative URL of the information for the item.
typeThe type of item represented by this Directory element.
titleThe name of the item.
agentThe agent used to set the metadata for the items in the library.
scannerThe 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.

Location Attributes
AttributeDescription
idThe unique identifier for the item.
pathThe 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:

Library Types
ValueLibrary Type
movieMovies, Other videos
showTV shows
artistMusic
photoPhotos

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

Movie and Other Video Agents
ValueName
tv.plex.agents.moviePlex Movie (Default: Movies)
com.plexapp.agents.nonePersonal media (Default: Other videos)
com.plexapp.agents.imdbPlex Movie (Legacy)
com.plexapp.agents.themoviedbThe Movie Database

TV shows

TV Shows Agents
ValueName
tv.plex.agents.seriesPlex TV Series (Default)
com.plexapp.agents.nonePersonal Media Shows
com.plexapp.agents.thetvdbTheTVDB
com.plexapp.agents.themoviedbThe Movie Database

Music

Music Agents
ValueName
tv.plex.agents.musicPlex Music (Default)
com.plexapp.agents.nonePersonal Media Artists
com.plexapp.agents.lastfmLast.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

Movies and TV Shows Languages
CodeLanguage
ar-SAArabic (Saudi Arabia)
bg-BGBulgarian
ca-ESCatalan
zh-CNChinese
zh-HKChinese (Hong Kong)
zh-TWChinese (Taiwan)
hr-HRCroatian
cs-CZCzech
da-DKDanish
nl-NLDutch
en-USEnglish
en-AUEnglish (Australia)
en-CAEnglish (Canada)
en-GBEnglish (UK)
et-EEEstonian
fi-FIFinnish
fr-FRFrench
fr-CAFrench (Canada)
de-DEGerman
el-GRGreek
he-ILHebrew
hi-INHindi
hu-HUHungarian
id-IDIndonesian
it-ITItalian
ja-JPJapanese
ko-KRKorean
lv-LVLatvian
lt-LTLithuanian
nb-NONorwegian Bokmål
fa-IRPersian
pl-PLPolish
pt-BRPortuguese
pt-PTPortuguese (Portugal)
ro-RORomanian
ru-RURussian
sk-SKSlovak
es-ESSpanish
es-MXSpanish (Mexico)
sv-SESwedish
th-THThai
tr-TRTurkish
uk-UAUkrainian
vi-VNVietnamese

Music and photos

Music and Photos Languages
CodeLanguage
idBahasa Indonesia
daDansk
deDeutsch
enEnglish
esEspañol
frFrançais
itItaliano
huMagyar
nlNederlands
nnNorsk nynorsk
plPolski
ptPortuguês
fiSuomeksi
svSvenska
viTiếng Việt
trTürkçe
xxUnknown
hrhrvatski
roromână
skslovenč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

Photos and Other Videos Languages
CodeLanguage
xnNone

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
The Movie Database Languages
ValueLanguage
0(Blank)
1Argentina
2Australia
3Austria
4Belgium
5Belize
6Bolivia
7Brazil
8Canada
9Chile
10Colombia
11Costa Rica
12Czech Republic
13Denmark
14Dominican Republic
15Ecuador
16El Salvador
17France
18Germany
19Guatemala
20Honduras
21Hong Kong SAR
22Ireland
23Italy
24Jamaica
25Korea
26Liechtenstein
27Luxembourg
28Mexico
29Netherlands
30New Zealand
31Nicaragua
32Panama
33Paraguay
34Peru
35Portugal
36Peoples Republic of China
37Puerto Rico
38Russia
39Singapore
40South Africa
41Spain
42Sweden
43Switzerland
44Taiwan
45Trinidad
46United Kingdom
47United States
48Uruguay
49Venezuela

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
Subscribe
Display