Files
plexjs/docs/sdks/plex

Plex

(plex)

Overview

API Calls that perform operations directly against https://Plex.tv

Available Operations

getCompanionsData

Get Companions Data

Example Usage

import { PlexAPI } from "@lukehagar/plexjs";

const plexAPI = new PlexAPI({
  accessToken: "<YOUR_API_KEY_HERE>",
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const result = await plexAPI.plex.getCompanionsData();
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { plexGetCompanionsData } from "@lukehagar/plexjs/funcs/plexGetCompanionsData.js";

// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
  accessToken: "<YOUR_API_KEY_HERE>",
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const res = await plexGetCompanionsData(plexAPI);

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

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.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use.

Response

Promise<operations.GetCompanionsDataResponse>

Errors

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

getUserFriends

Get friends of provided auth token.

Example Usage

import { PlexAPI } from "@lukehagar/plexjs";

const plexAPI = new PlexAPI({
  accessToken: "<YOUR_API_KEY_HERE>",
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const result = await plexAPI.plex.getUserFriends();
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { plexGetUserFriends } from "@lukehagar/plexjs/funcs/plexGetUserFriends.js";

// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
  accessToken: "<YOUR_API_KEY_HERE>",
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const res = await plexGetUserFriends(plexAPI);

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

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.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use.

Response

Promise<operations.GetUserFriendsResponse>

Errors

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

getGeoData

Returns the geolocation and locale data of the caller

Example Usage

import { PlexAPI } from "@lukehagar/plexjs";

const plexAPI = new PlexAPI({
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const result = await plexAPI.plex.getGeoData();
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { plexGetGeoData } from "@lukehagar/plexjs/funcs/plexGetGeoData.js";

// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const res = await plexGetGeoData(plexAPI);

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

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.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use.

Response

Promise<operations.GetGeoDataResponse>

Errors

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

getHomeData

Retrieves the home data for the authenticated user, including details like home ID, name, guest access information, and subscription status.

Example Usage

import { PlexAPI } from "@lukehagar/plexjs";

const plexAPI = new PlexAPI({
  accessToken: "<YOUR_API_KEY_HERE>",
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const result = await plexAPI.plex.getHomeData();
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { plexGetHomeData } from "@lukehagar/plexjs/funcs/plexGetHomeData.js";

// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
  accessToken: "<YOUR_API_KEY_HERE>",
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const res = await plexGetHomeData(plexAPI);

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

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.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.GetHomeDataResponse>

Errors

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

getServerResources

Get Plex server access tokens and server connections

Example Usage

import { PlexAPI } from "@lukehagar/plexjs";
import { IncludeHttps, IncludeIPv6, IncludeRelay } from "@lukehagar/plexjs/sdk/models/operations";

const plexAPI = new PlexAPI({
  accessToken: "<YOUR_API_KEY_HERE>",
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const result = await plexAPI.plex.getServerResources({
    xPlexToken: "CV5xoxjTpFKUzBTShsaf",
    includeHttps: IncludeHttps.One,
    includeRelay: IncludeRelay.One,
    includeIPv6: IncludeIPv6.One,
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { plexGetServerResources } from "@lukehagar/plexjs/funcs/plexGetServerResources.js";
import { IncludeHttps, IncludeIPv6, IncludeRelay } from "@lukehagar/plexjs/sdk/models/operations";

// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
  accessToken: "<YOUR_API_KEY_HERE>",
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const res = await plexGetServerResources(plexAPI, {
    xPlexToken: "CV5xoxjTpFKUzBTShsaf",
    includeHttps: IncludeHttps.One,
    includeRelay: IncludeRelay.One,
    includeIPv6: IncludeIPv6.One,
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.GetServerResourcesRequest ✔️ The request object to use for the request.
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.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use.

Response

Promise<operations.GetServerResourcesResponse>

Errors

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

getPin

Retrieve a Pin from Plex.tv for authentication flows

Example Usage

import { PlexAPI } from "@lukehagar/plexjs";

const plexAPI = new PlexAPI({
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const result = await plexAPI.plex.getPin("gcgzw5rz2xovp84b4vha3a40", "Plex Web");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { plexGetPin } from "@lukehagar/plexjs/funcs/plexGetPin.js";

// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const res = await plexGetPin(plexAPI, "gcgzw5rz2xovp84b4vha3a40", "Plex Web");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description Example
strong boolean Determines the kind of code returned by the API call
Strong codes are used for Pin authentication flows
Non-Strong codes are used for Plex.tv/link
xPlexClientIdentifier string The unique identifier for the client application
This is used to track the client application and its usage
(UUID, serial number, or other number unique per device)
[object Object]
xPlexProduct string N/A [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.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use. http://localhost:8080

Response

Promise<operations.GetPinResponse>

Errors

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

getTokenByPinId

Retrieve an Access Token from Plex.tv after the Pin has been authenticated

Example Usage

import { PlexAPI } from "@lukehagar/plexjs";

const plexAPI = new PlexAPI({
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const result = await plexAPI.plex.getTokenByPinId(408895, "gcgzw5rz2xovp84b4vha3a40");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { plexGetTokenByPinId } from "@lukehagar/plexjs/funcs/plexGetTokenByPinId.js";

// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
  xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});

async function run() {
  const res = await plexGetTokenByPinId(plexAPI, 408895, "gcgzw5rz2xovp84b4vha3a40");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description Example
pinID number ✔️ The PinID to retrieve an access token for
xPlexClientIdentifier string The unique identifier for the client application
This is used to track the client application and its usage
(UUID, serial number, or other number unique per device)
[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.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use. http://localhost:8080

Response

Promise<operations.GetTokenByPinIdResponse>

Errors

Error Object Status Code Content Type
errors.GetTokenByPinIdResponseBody 400 application/json
errors.GetTokenByPinIdPlexResponseBody 404 application/json
errors.SDKError 4xx-5xx /