mirror of
https://github.com/LukeHagar/plexphp.git
synced 2025-12-06 04:20:51 +00:00
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
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
$sdk = Plex_API\PlexAPI::builder()
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$response = $sdk->plex->getCompanionsData(
);
if ($response->responseBodies !== null) {
// handle response
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$serverURL |
string | ➖ | An optional server URL to use. |
Response
?Operations\GetCompanionsDataResponse
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\GetCompanionsDataBadRequest | 400 | application/json |
| Errors\GetCompanionsDataUnauthorized | 401 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |
getUserFriends
Get friends of provided auth token.
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
$sdk = Plex_API\PlexAPI::builder()
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$response = $sdk->plex->getUserFriends(
);
if ($response->friends !== null) {
// handle response
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$serverURL |
string | ➖ | An optional server URL to use. |
Response
?Operations\GetUserFriendsResponse
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\GetUserFriendsBadRequest | 400 | application/json |
| Errors\GetUserFriendsUnauthorized | 401 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |
getGeoData
Returns the geolocation and locale data of the caller
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
$sdk = Plex_API\PlexAPI::builder()->build();
$response = $sdk->plex->getGeoData(
);
if ($response->geoData !== null) {
// handle response
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$serverURL |
string | ➖ | An optional server URL to use. |
Response
?Operations\GetGeoDataResponse
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\GetGeoDataBadRequest | 400 | application/json |
| Errors\GetGeoDataUnauthorized | 401 | application/json |
| Errors\SDKException | 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
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
$sdk = Plex_API\PlexAPI::builder()
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$response = $sdk->plex->getHomeData(
);
if ($response->object !== null) {
// handle response
}
Response
?Operations\GetHomeDataResponse
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\GetHomeDataBadRequest | 400 | application/json |
| Errors\GetHomeDataUnauthorized | 401 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |
getServerResources
Get Plex server access tokens and server connections
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Operations;
$sdk = Plex_API\PlexAPI::builder()
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$response = $sdk->plex->getServerResources(
clientID: '3381b62b-9ab7-4e37-827b-203e9809eb58',
includeHttps: Operations\IncludeHttps::Enable,
includeRelay: Operations\IncludeRelay::Enable,
includeIPv6: Operations\IncludeIPv6::Enable
);
if ($response->plexDevices !== null) {
// handle response
}
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
clientID |
string | ✔️ | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
includeHttps |
?Operations\IncludeHttps | ➖ | Include Https entries in the results | 1 |
includeRelay |
?Operations\IncludeRelay | ➖ | Include Relay addresses in the results E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400 |
1 |
includeIPv6 |
?Operations\IncludeIPv6 | ➖ | Include IPv6 entries in the results | 1 |
$serverURL |
string | ➖ | An optional server URL to use. | http://localhost:8080 |
Response
?Operations\GetServerResourcesResponse
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\GetServerResourcesBadRequest | 400 | application/json |
| Errors\GetServerResourcesUnauthorized | 401 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |
getPin
Retrieve a Pin ID from Plex.tv to use for authentication flows
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Operations;
$sdk = Plex_API\PlexAPI::builder()->build();
$request = new Operations\GetPinRequest(
clientID: '3381b62b-9ab7-4e37-827b-203e9809eb58',
clientName: 'Plex for Roku',
deviceNickname: 'Roku 3',
clientVersion: '2.4.1',
platform: 'Roku',
);
$response = $sdk->plex->getPin(
request: $request
);
if ($response->authPinContainer !== null) {
// handle response
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$request |
Operations\GetPinRequest | ✔️ | The request object to use for the request. |
$serverURL |
string | ➖ | An optional server URL to use. |
Response
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\GetPinBadRequest | 400 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |
getTokenByPinId
Retrieve an Access Token from Plex.tv after the Pin has been authenticated
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Operations;
$sdk = Plex_API\PlexAPI::builder()->build();
$request = new Operations\GetTokenByPinIdRequest(
pinID: 232248,
clientID: '3381b62b-9ab7-4e37-827b-203e9809eb58',
clientName: 'Plex for Roku',
deviceNickname: 'Roku 3',
clientVersion: '2.4.1',
platform: 'Roku',
);
$response = $sdk->plex->getTokenByPinId(
request: $request
);
if ($response->authPinContainer !== null) {
// handle response
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$request |
Operations\GetTokenByPinIdRequest | ✔️ | The request object to use for the request. |
$serverURL |
string | ➖ | An optional server URL to use. |
Response
?Operations\GetTokenByPinIdResponse
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\GetTokenByPinIdBadRequest | 400 | application/json |
| Errors\GetTokenByPinIdResponseBody | 404 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |