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

12 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

<?php

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->twoHundredApplicationJsonObject !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Response

?\LukeHagar\Plex_API\Models\Operations\GetHomeDataResponse

getPin

Retrieve a Pin from Plex.tv for authentication flows

Example Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use \LukeHagar\Plex_API;
use \LukeHagar\Plex_API\Models\Components;
use \LukeHagar\Plex_API\Models\Operations;

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

try {
    

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

    if ($response->twoHundredAndOneApplicationJsonObject !== 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

?\LukeHagar\Plex_API\Models\Operations\GetPinResponse

getToken

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

Example Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use \LukeHagar\Plex_API;
use \LukeHagar\Plex_API\Models\Components;
use \LukeHagar\Plex_API\Models\Operations;

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

try {
    

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

    if ($response->twoHundredApplicationJsonObject !== 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

?\LukeHagar\Plex_API\Models\Operations\GetTokenResponse