mirror of
https://github.com/LukeHagar/plexphp.git
synced 2025-12-06 04:20:51 +00:00
13 KiB
13 KiB
Sessions
Overview
API Calls that perform search operations with Plex Media Server Sessions
Available Operations
- getSessions - Get Active Sessions
- getSessionHistory - Get Session History
- getTranscodeSessions - Get Transcode Sessions
- stopTranscodeSession - Stop a Transcode Session
getSessions
This will retrieve the "Now Playing" Information of the PMS.
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Components;
$security = new Components\Security(
accessToken: "<YOUR_API_KEY_HERE>",
);
$sdk = Plex_API\PlexAPI::builder()
->setClientID('gcgzw5rz2xovp84b4vha3a40')
->setClientName('Plex Web')
->setClientVersion('4.133.0')
->setClientPlatform('Chrome')
->setDeviceName('Linux')
->setSecurity($security)->build();
try {
$response = $sdk->sessions->getSessions();
if ($response->object !== null) {
// handle response
}
} catch (Throwable $e) {
// handle exception
}
Response
?Operations\GetSessionsResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| Errors\GetSessionsBadRequest | 400 | application/json |
| Errors\GetSessionsUnauthorized | 401 | application/json |
| LukeHagar\Plex_API\Models\Errors.SDKException | 4xx-5xx | / |
getSessionHistory
This will Retrieve a listing of all history views.
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Components;
use LukeHagar\Plex_API\Models\Operations;
$security = new Components\Security(
accessToken: "<YOUR_API_KEY_HERE>",
);
$sdk = Plex_API\PlexAPI::builder()
->setClientID('gcgzw5rz2xovp84b4vha3a40')
->setClientName('Plex Web')
->setClientVersion('4.133.0')
->setClientPlatform('Chrome')
->setDeviceName('Linux')
->setSecurity($security)->build();
try {
$filter = new Operations\QueryParamFilter();
$response = $sdk->sessions->getSessionHistory('<value>', 1, $filter, 12);
if ($response->object !== null) {
// handle response
}
} catch (Throwable $e) {
// handle exception
}
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
sort |
string | ➖ | Sorts the results by the specified field followed by the direction (asc, desc) |
|
accountId |
int | ➖ | Filter results by those that are related to a specific users id |
1 |
filter |
Operations\QueryParamFilter | ➖ | Filters content by field and direction/equality (Unknown if viewedAt is the only supported column) |
{ "viewed-at-greater-than": { "value": "viewedAt\u003e" }, "viewed-at-greater-than-or-equal-to": { "value": "viewedAt\u003e=\u003e" }, "viewed-at-less-than": { "value": "viewedAt\u003c" } } |
librarySectionID |
int | ➖ | Filters the results based on the id of a valid library section |
12 |
Response
?Operations\GetSessionHistoryResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| Errors\GetSessionHistoryBadRequest | 400 | application/json |
| Errors\GetSessionHistoryUnauthorized | 401 | application/json |
| LukeHagar\Plex_API\Models\Errors.SDKException | 4xx-5xx | / |
getTranscodeSessions
Get Transcode Sessions
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Components;
$security = new Components\Security(
accessToken: "<YOUR_API_KEY_HERE>",
);
$sdk = Plex_API\PlexAPI::builder()
->setClientID('gcgzw5rz2xovp84b4vha3a40')
->setClientName('Plex Web')
->setClientVersion('4.133.0')
->setClientPlatform('Chrome')
->setDeviceName('Linux')
->setSecurity($security)->build();
try {
$response = $sdk->sessions->getTranscodeSessions();
if ($response->object !== null) {
// handle response
}
} catch (Throwable $e) {
// handle exception
}
Response
?Operations\GetTranscodeSessionsResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| Errors\GetTranscodeSessionsBadRequest | 400 | application/json |
| Errors\GetTranscodeSessionsUnauthorized | 401 | application/json |
| LukeHagar\Plex_API\Models\Errors.SDKException | 4xx-5xx | / |
stopTranscodeSession
Stop a Transcode Session
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Components;
$security = new Components\Security(
accessToken: "<YOUR_API_KEY_HERE>",
);
$sdk = Plex_API\PlexAPI::builder()
->setClientID('gcgzw5rz2xovp84b4vha3a40')
->setClientName('Plex Web')
->setClientVersion('4.133.0')
->setClientPlatform('Chrome')
->setDeviceName('Linux')
->setSecurity($security)->build();
try {
$response = $sdk->sessions->stopTranscodeSession('zz7llzqlx8w9vnrsbnwhbmep');
if ($response->statusCode === 200) {
// handle response
}
} catch (Throwable $e) {
// handle exception
}
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
sessionKey |
string | ✔️ | the Key of the transcode session to stop | zz7llzqlx8w9vnrsbnwhbmep |
Response
?Operations\StopTranscodeSessionResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| Errors\StopTranscodeSessionBadRequest | 400 | application/json |
| Errors\StopTranscodeSessionUnauthorized | 401 | application/json |
| LukeHagar\Plex_API\Models\Errors.SDKException | 4xx-5xx | / |