Files
plexjs/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

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const url = "file://C:\Image.png&type=13";
  const type = 4462.17;
  
  const res = await sdk.library.getFileHash(url, type);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description Example
url string ✔️ This is the path to the local file, must be prefixed by file:// [object Object]
type number Item type
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetFileHashResponse>

Errors

Error Object Status Code Content Type
errors.GetFileHashResponseBody 401 application/json
errors.SDKError 4xx-5xx /

getRecentlyAdded

This endpoint will return the recently added content.

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const res = await sdk.library.getRecentlyAdded();

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetRecentlyAddedResponse>

Errors

Error Object Status Code Content Type
errors.GetRecentlyAddedResponseBody 401 application/json
errors.SDKError 4xx-5xx /

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

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const res = await sdk.library.getLibraries();

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetLibrariesResponse>

Errors

Error Object Status Code Content Type
errors.GetLibrariesResponseBody 401 application/json
errors.SDKError 4xx-5xx /

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

import { SDK } from "openapi";
import { IncludeDetails } from "openapi/models/operations";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const sectionId = 1000;
  const includeDetails = IncludeDetails.Zero;
  
  const res = await sdk.library.getLibrary(sectionId, includeDetails);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description Example
sectionId number ✔️ the Id of the library to query [object Object]
includeDetails operations.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.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetLibraryResponse>

Errors

Error Object Status Code Content Type
errors.GetLibraryResponseBody 401 application/json
errors.SDKError 4xx-5xx /

deleteLibrary

Delate a library using a specific section

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const sectionId = 1000;
  
  const res = await sdk.library.deleteLibrary(sectionId);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description Example
sectionId number ✔️ the Id of the library to query [object Object]
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.DeleteLibraryResponse>

Errors

Error Object Status Code Content Type
errors.DeleteLibraryResponseBody 401 application/json
errors.SDKError 4xx-5xx /

getLibraryItems

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

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const sectionId = 4510.92;
  const type = 760.66;
  const filter = "string";
  
  const res = await sdk.library.getLibraryItems(sectionId, type, filter);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
sectionId number ✔️ the Id of the library to query
type number item type
filter string the filter parameter
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetLibraryItemsResponse>

Errors

Error Object Status Code Content Type
errors.GetLibraryItemsResponseBody 401 application/json
errors.SDKError 4xx-5xx /

refreshLibrary

This endpoint Refreshes the library.

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const sectionId = 934.16;
  
  const res = await sdk.library.refreshLibrary(sectionId);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
sectionId number ✔️ the Id of the library to refresh
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.RefreshLibraryResponse>

Errors

Error Object Status Code Content Type
errors.RefreshLibraryResponseBody 401 application/json
errors.SDKError 4xx-5xx /

getLatestLibraryItems

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

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const sectionId = 7171.54;
  const type = 8015.12;
  const filter = "string";
  
  const res = await sdk.library.getLatestLibraryItems(sectionId, type, filter);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
sectionId number ✔️ the Id of the library to query
type number ✔️ item type
filter string the filter parameter
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetLatestLibraryItemsResponse>

Errors

Error Object Status Code Content Type
errors.GetLatestLibraryItemsResponseBody 401 application/json
errors.SDKError 4xx-5xx /

getCommonLibraryItems

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

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const sectionId = 2710.37;
  const type = 2760.31;
  const filter = "string";
  
  const res = await sdk.library.getCommonLibraryItems(sectionId, type, filter);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
sectionId number ✔️ the Id of the library to query
type number ✔️ item type
filter string the filter parameter
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetCommonLibraryItemsResponse>

Errors

Error Object Status Code Content Type
errors.GetCommonLibraryItemsResponseBody 401 application/json
errors.SDKError 4xx-5xx /

getMetadata

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

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const ratingKey = 8382.31;
  
  const res = await sdk.library.getMetadata(ratingKey);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
ratingKey number ✔️ the id of the library item to return the children of.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetMetadataResponse>

Errors

Error Object Status Code Content Type
errors.GetMetadataResponseBody 401 application/json
errors.SDKError 4xx-5xx /

getMetadataChildren

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

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const ratingKey = 1539.14;
  
  const res = await sdk.library.getMetadataChildren(ratingKey);

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
ratingKey number ✔️ the id of the library item to return the children of.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetMetadataChildrenResponse>

Errors

Error Object Status Code Content Type
errors.GetMetadataChildrenResponseBody 401 application/json
errors.SDKError 4xx-5xx /

getOnDeck

This endpoint will return the on deck content.

Example Usage

import { SDK } from "openapi";

async function run() {
  const sdk = new SDK({
    accessToken: "<YOUR_API_KEY_HERE>",
  });

  const res = await sdk.library.getOnDeck();

  if (res?.statusCode !== 200) {
    throw new Error("Unexpected status code: " + res?.statusCode || "-");
  }
  
  // handle response
}

run();

Parameters

Parameter Type Required Description
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetOnDeckResponse>

Errors

Error Object Status Code Content Type
errors.GetOnDeckResponseBody 401 application/json
errors.SDKError 4xx-5xx /