Files
plexcsharp/docs/sdks/library

Library

(Library)

Overview

API Calls interacting with Plex Media Server Libraries

Available Operations

GetFileHash

This resource returns hash values for local files

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetFileHashAsync(Url: "file://C:\Image.png&type=13", Type: 4462.17D);

// handle response

Parameters

Parameter Type Required Description Example
Url string ✔️ This is the path to the local file, must be prefixed by file:// file://C:\Image.png&type=13
Type double Item type

Response

GetFileHashResponse

GetRecentlyAdded

This endpoint will return the recently added content.

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetRecentlyAddedAsync();

// handle response

Response

GetRecentlyAddedResponse

GetLibraries

A library section (commonly referred to as just a library) is a collection of media. Libraries are typed, and depending on their type provide either a flat or a hierarchical view of the media. For example, a music library has an artist > albums > tracks structure, whereas a movie library is flat.

Libraries have features beyond just being a collection of media; for starters, they include information about supported types, filters and sorts. This allows a client to provide a rich interface around the media (e.g. allow sorting movies by release year).

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetLibrariesAsync();

// handle response

Response

GetLibrariesResponse

GetLibrary

Returns details for the library. This can be thought of as an interstitial endpoint because it contains information about the library, rather than content itself. These details are:

  • A list of Directory objects: These used to be used by clients to build a menuing system. There are four flavors of directory found here:
    • Primary: (e.g. all, On Deck) These are still used in some clients to provide "shortcuts" to subsets of media. However, with the exception of On Deck, all of them can be created by media queries, and the desire is to allow these to be customized by users.
    • Secondary: These are marked with secondary="1" and were used by old clients to provide nested menus allowing for primative (but structured) navigation.
    • Special: There is a By Folder entry which allows browsing the media by the underlying filesystem structure, and there's a completely obsolete entry marked search="1" which used to be used to allow clients to build search dialogs on the fly.
  • A list of Type objects: These represent the types of things found in this library, and for each one, a list of Filter and Sort objects. These can be used to build rich controls around a grid of media to allow filtering and organizing. Note that these filters and sorts are optional, and without them, the client won't render any filtering controls. The Type object contains:
    • key: This provides the root endpoint returning the actual media list for the type.
    • type: This is the metadata type for the type (if a standard Plex type).
    • title: The title for for the content of this type (e.g. "Movies").
  • Each Filter object contains a description of the filter. Note that it is not an exhaustive list of the full media query language, but an inportant subset useful for top-level API.
    • filter: This represents the filter name used for the filter, which can be used to construct complex media queries with.
    • filterType: This is either string, integer, or boolean, and describes the type of values used for the filter.
    • key: This provides the endpoint where the possible range of values for the filter can be retrieved (e.g. for a "Genre" filter, it returns a list of all the genres in the library). This will include a type argument that matches the metadata type of the Type element.
    • title: The title for the filter.
  • Each Sort object contains a description of the sort field.
    • defaultDirection: Can be either asc or desc, and specifies the default direction for the sort field (e.g. titles default to alphabetically ascending).
    • descKey and key: Contains the parameters passed to the sort=... media query for each direction of the sort.
    • title: The title of the field.

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetLibraryAsync(SectionId: 1000D, IncludeDetails: IncludeDetails.Zero);

// handle response

Parameters

Parameter Type Required Description Example
SectionId double ✔️ the Id of the library to query 1000
IncludeDetails IncludeDetails Whether or not to include details for a section (types, filters, and sorts).
Only exists for backwards compatibility, media providers other than the server libraries have it on always.

Response

GetLibraryResponse

DeleteLibrary

Delate a library using a specific section

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.DeleteLibraryAsync(SectionId: 1000D);

// handle response

Parameters

Parameter Type Required Description Example
SectionId double ✔️ the Id of the library to query 1000

Response

DeleteLibraryResponse

GetLibraryItems

This endpoint will return a list of library items filtered by the filter and type provided

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetLibraryItemsAsync(SectionId: 4510.92D, Type: 760.66D, Filter: "string");

// handle response

Parameters

Parameter Type Required Description
SectionId double ✔️ the Id of the library to query
Type double item type
Filter string the filter parameter

Response

GetLibraryItemsResponse

RefreshLibrary

This endpoint Refreshes the library.

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.RefreshLibraryAsync(SectionId: 934.16D);

// handle response

Parameters

Parameter Type Required Description
SectionId double ✔️ the Id of the library to refresh

Response

RefreshLibraryResponse

GetLatestLibraryItems

This endpoint will return a list of the latest library items filtered by the filter and type provided

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetLatestLibraryItemsAsync(SectionId: 7171.54D, Type: 8015.12D, Filter: "string");

// handle response

Parameters

Parameter Type Required Description
SectionId double ✔️ the Id of the library to query
Type double ✔️ item type
Filter string the filter parameter

Response

GetLatestLibraryItemsResponse

GetCommonLibraryItems

Represents a "Common" item. It contains only the common attributes of the items selected by the provided filter

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetCommonLibraryItemsAsync(SectionId: 2710.37D, Type: 2760.31D, Filter: "string");

// handle response

Parameters

Parameter Type Required Description
SectionId double ✔️ the Id of the library to query
Type double ✔️ item type
Filter string the filter parameter

Response

GetCommonLibraryItemsResponse

GetMetadata

This endpoint will return the metadata of a library item specified with the ratingKey.

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetMetadataAsync(RatingKey: 8382.31D);

// handle response

Parameters

Parameter Type Required Description
RatingKey double ✔️ the id of the library item to return the children of.

Response

GetMetadataResponse

GetMetadataChildren

This endpoint will return the children of of a library item specified with the ratingKey.

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;
using PlexAPI.Models.Requests;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetMetadataChildrenAsync(RatingKey: 1539.14D);

// handle response

Parameters

Parameter Type Required Description
RatingKey double ✔️ the id of the library item to return the children of.

Response

GetMetadataChildrenResponse

GetOnDeck

This endpoint will return the on deck content.

Example Usage

using PlexAPI;
using PlexAPI.Models.Components;

var sdk = new PlexAPISDK(
    security: new Models.Components.Security() {
        AccessToken = "<YOUR_API_KEY_HERE>",
    });

var res = await sdk.Library.GetOnDeckAsync();

// handle response

Response

GetOnDeckResponse