mirror of
https://github.com/LukeHagar/plexjs.git
synced 2025-12-06 04:20:46 +00:00
14 KiB
14 KiB
Activities
(activities)
Overview
Activities are awesome. They provide a way to monitor and control asynchronous operations on the server. In order to receive real-time updates for activities, a client would normally subscribe via either EventSource or Websocket endpoints.
Activities are associated with HTTP replies via a special X-Plex-Activity header which contains the UUID of the activity.
Activities are optional cancellable. If cancellable, they may be cancelled via the DELETE endpoint. Other details:
- They can contain a
progress(from 0 to 100) marking the percent completion of the activity. - They must contain an
typewhich is used by clients to distinguish the specific activity. - They may contain a
Contextobject with attributes which associate the activity with various specific entities (items, libraries, etc.) - The may contain a
Responseobject which attributes which represent the result of the asynchronous operation.
Available Operations
- getServerActivities - Get Server Activities
- cancelServerActivities - Cancel Server Activities
getServerActivities
Get Server Activities
Example Usage
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
clientID: "gcgzw5rz2xovp84b4vha3a40",
clientName: "Plex Web",
clientVersion: "4.133.0",
clientPlatform: "Chrome",
deviceName: "Linux",
});
async function run() {
const result = await plexAPI.activities.getServerActivities();
// Handle the result
console.log(result);
}
run();
Standalone function
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { activitiesGetServerActivities } from "@lukehagar/plexjs/funcs/activitiesGetServerActivities.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>",
clientID: "gcgzw5rz2xovp84b4vha3a40",
clientName: "Plex Web",
clientVersion: "4.133.0",
clientPlatform: "Chrome",
deviceName: "Linux",
});
async function run() {
const res = await activitiesGetServerActivities(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.GetServerActivitiesResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.GetServerActivitiesBadRequest | 400 | application/json |
| errors.GetServerActivitiesUnauthorized | 401 | application/json |
| errors.SDKError | 4XX, 5XX | */* |
cancelServerActivities
Cancel Server Activities
Example Usage
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
clientID: "gcgzw5rz2xovp84b4vha3a40",
clientName: "Plex Web",
clientVersion: "4.133.0",
clientPlatform: "Chrome",
deviceName: "Linux",
});
async function run() {
const result = await plexAPI.activities.cancelServerActivities("25b71ed5-0f9d-461c-baa7-d404e9e10d3e");
// Handle the result
console.log(result);
}
run();
Standalone function
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { activitiesCancelServerActivities } from "@lukehagar/plexjs/funcs/activitiesCancelServerActivities.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>",
clientID: "gcgzw5rz2xovp84b4vha3a40",
clientName: "Plex Web",
clientVersion: "4.133.0",
clientPlatform: "Chrome",
deviceName: "Linux",
});
async function run() {
const res = await activitiesCancelServerActivities(plexAPI, "25b71ed5-0f9d-461c-baa7-d404e9e10d3e");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
activityUUID |
string | ✔️ | The UUID of the activity to cancel. | [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. |
Response
Promise<operations.CancelServerActivitiesResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.CancelServerActivitiesBadRequest | 400 | application/json |
| errors.CancelServerActivitiesUnauthorized | 401 | application/json |
| errors.SDKError | 4XX, 5XX | */* |