52 KiB
Plex
(plex)
Overview
API Calls that perform operations directly against https://Plex.tv
Available Operations
- getCompanionsData - Get Companions Data
- getUserFriends - Get list of friends of the user logged in
- getGeoData - Get Geo Data
- getHomeData - Get Plex Home Data
- getServerResources - Get Server Resources
- getPin - Get a Pin
- getTokenByPinId - Get Access Token by PinId
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.GetCompanionsDataBadRequest | 400 | application/json |
| errors.GetCompanionsDataUnauthorized | 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.GetUserFriendsBadRequest | 400 | application/json |
| errors.GetUserFriendsUnauthorized | 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.GetGeoDataBadRequest | 400 | application/json |
| errors.GetGeoDataUnauthorized | 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.GetHomeDataBadRequest | 400 | application/json |
| errors.GetHomeDataUnauthorized | 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("gcgzw5rz2xovp84b4vha3a40", IncludeHttps.One, IncludeRelay.One, 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, "gcgzw5rz2xovp84b4vha3a40", IncludeHttps.One, IncludeRelay.One, IncludeIPv6.One);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
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] |
includeHttps |
operations.IncludeHttps | ➖ | Include Https entries in the results | [object Object] |
includeRelay |
operations.IncludeRelay | ➖ | Include Relay addresses in the results E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400 |
[object Object] |
includeIPv6 |
operations.IncludeIPv6 | ➖ | Include IPv6 entries in the results | [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.GetServerResourcesResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.GetServerResourcesBadRequest | 400 | application/json |
| errors.GetServerResourcesUnauthorized | 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.GetPinBadRequest | 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.GetTokenByPinIdBadRequest | 400 | application/json |
| errors.GetTokenByPinIdResponseBody | 404 | application/json |
| errors.SDKError | 4xx-5xx | / |