(sessions)
API Calls that perform search operations with Plex Media Server Sessions
- getSessions - Get Active Sessions
- getSessionHistory - Get Session History
- getTranscodeSessions - Get Transcode Sessions
- stopTranscodeSession - Stop a Transcode Session
This will retrieve the "Now Playing" Information of the PMS.
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await plexAPI.sessions.getSessions();
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { sessionsGetSessions } from "@lukehagar/plexjs/funcs/sessionsGetSessions.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>",
});
async function run() {
const res = await sessionsGetSessions(plexAPI);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
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. |
Promise<operations.GetSessionsResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.GetSessionsBadRequest | 400 | application/json |
errors.GetSessionsUnauthorized | 401 | application/json |
errors.SDKError | 4XX, 5XX | */* |
This will Retrieve a listing of all history views.
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await plexAPI.sessions.getSessionHistory("viewedAt:desc", 1, {}, 12);
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { sessionsGetSessionHistory } from "@lukehagar/plexjs/funcs/sessionsGetSessionHistory.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>",
});
async function run() {
const res = await sessionsGetSessionHistory(plexAPI, "viewedAt:desc", 1, {}, 12);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
sort |
string | ➖ | Sorts the results by the specified field followed by the direction (asc, desc) |
|
accountId |
number | ➖ | Filter results by those that are related to a specific users id |
[object Object] |
filter |
operations.QueryParamFilter | ➖ | Filters content by field and direction/equality (Unknown if viewedAt is the only supported column) |
[object Object] |
librarySectionID |
number | ➖ | Filters the results based on the id of a valid library section |
[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. |
Promise<operations.GetSessionHistoryResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.GetSessionHistoryBadRequest | 400 | application/json |
errors.GetSessionHistoryUnauthorized | 401 | application/json |
errors.SDKError | 4XX, 5XX | */* |
Get Transcode Sessions
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await plexAPI.sessions.getTranscodeSessions();
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { sessionsGetTranscodeSessions } from "@lukehagar/plexjs/funcs/sessionsGetTranscodeSessions.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>",
});
async function run() {
const res = await sessionsGetTranscodeSessions(plexAPI);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
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. |
Promise<operations.GetTranscodeSessionsResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.GetTranscodeSessionsBadRequest | 400 | application/json |
errors.GetTranscodeSessionsUnauthorized | 401 | application/json |
errors.SDKError | 4XX, 5XX | */* |
Stop a Transcode Session
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await plexAPI.sessions.stopTranscodeSession("zz7llzqlx8w9vnrsbnwhbmep");
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { sessionsStopTranscodeSession } from "@lukehagar/plexjs/funcs/sessionsStopTranscodeSession.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>",
});
async function run() {
const res = await sessionsStopTranscodeSession(plexAPI, "zz7llzqlx8w9vnrsbnwhbmep");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
sessionKey |
string | ✔️ | the Key of the transcode session to stop | [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. |
Promise<operations.StopTranscodeSessionResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.StopTranscodeSessionBadRequest | 400 | application/json |
errors.StopTranscodeSessionUnauthorized | 401 | application/json |
errors.SDKError | 4XX, 5XX | */* |