Files
plexphp/docs/sdks/plex/README.md

13 KiB
Raw Blame History

Plex

Overview

API Calls that perform operations directly against https://Plex.tv

Available Operations

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;
use LukeHagar\Plex_API\Models\Components;

$security = new Components\Security();
$security->accessToken = '<YOUR_API_KEY_HERE>';

$sdk = Plex_API\PlexAPI::builder()
    ->setXPlexClientIdentifier('Postman')
    ->setSecurity($security)->build();

try {
    $response = $sdk->plex->getHomeData();

    if ($response->object !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Response

?Operations\GetHomeDataResponse

Errors

Error Object Status Code Content Type
Errors\GetHomeDataResponseBody 401 application/json
LukeHagar\Plex_API\Models\Errors.SDKException 4xx-5xx /

getPin

Retrieve a Pin from Plex.tv for authentication flows

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use LukeHagar\Plex_API;

$sdk = Plex_API\PlexAPI::builder()
    ->setXPlexClientIdentifier('Postman')
    ->build();

try {

    $response = $sdk->plex->getPin('Postman', false, 'Postman');

    if ($response->object !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Parameters

Parameter Type Required Description Example
xPlexProduct string ✔️ Product name of the application shown in the list of devices
Postman
strong bool 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)
Postman
$serverURL string An optional server URL to use. http://localhost:8080

Response

?Operations\GetPinResponse

Errors

Error Object Status Code Content Type
Errors\GetPinResponseBody 400 application/json
LukeHagar\Plex_API\Models\Errors.SDKException 4xx-5xx /

getToken

Retrieve an Access Token from Plex.tv after the Pin has already been authenticated

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use LukeHagar\Plex_API;

$sdk = Plex_API\PlexAPI::builder()
    ->setXPlexClientIdentifier('Postman')
    ->build();

try {

    $response = $sdk->plex->getToken('<value>', 'Postman');

    if ($response->object !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Parameters

Parameter Type Required Description Example
pinID string ✔️ 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)
Postman
$serverURL string An optional server URL to use. http://localhost:8080

Response

?Operations\GetTokenResponse

Errors

Error Object Status Code Content Type
Errors\GetTokenResponseBody 400 application/json
LukeHagar\Plex_API\Models\Errors.SDKException 4xx-5xx /