Plex-API: An Open API Spec for interacting with Plex.tv and Plex Media Server
An Open Source OpenAPI Specification for Plex Media Server
Automation and SDKs provided by Speakeasy
The following SDKs are generated from the OpenAPI Specification. They are automatically generated and may not be fully tested. If you find any issues, please open an issue on the main specification Repository.
Language | Repository | Releases | Other |
---|---|---|---|
Python | GitHub | PyPI | - |
JavaScript/TypeScript | GitHub | NPM \ JSR | - |
Go | GitHub | Releases | GoDoc |
Ruby | GitHub | Releases | - |
Swift | GitHub | Releases | - |
PHP | GitHub | Releases | - |
Java | GitHub | Releases | - |
C# | GitHub | Releases | - |
The SDK relies on Composer to manage its dependencies.
To install the SDK and add it as a dependency to an existing composer.json
file:
composer require "lukehagar/plex-api"
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
$security = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()->setSecurity($security)->build();
$response = $sdk->server->getServerCapabilities(
);
if ($response->object !== null) {
// handle response
}
Available methods
- cancelServerActivities - Cancel Server Activities
- getServerActivities - Get Server Activities
- getSourceConnectionInformation - Get Source Connection Information
- getTokenDetails - Get Token Details
- getTransientToken - Get a Transient Token
- postUsersSignInData - Get User Sign In Data
- getButlerTasks - Get Butler tasks
- startAllTasks - Start all Butler tasks
- startTask - Start a single Butler task
- stopAllTasks - Stop all Butler tasks
- stopTask - Stop a single Butler task
- getRecentlyAdded - Get Recently Added
- getGlobalHubs - Get Global Hubs
- getLibraryHubs - Get library specific hubs
- deleteLibrary - Delete Library Section
- getAllLibraries - Get All Libraries
- getLibraryDetails - Get Library Details
- getLibraryItems - Get Library Items
- getMetaDataByRatingKey - Get Metadata by RatingKey
- getRecentlyAddedLibrary - Get Recently Added
- getRefreshLibraryMetadata - Refresh Metadata Of The Library
- getSearchAllLibraries - Search All Libraries
- getSearchLibrary - Search Library
- getFileHash - Get Hash Value
- getMetadataChildren - Get Items Children
- getOnDeck - Get On Deck
- getTopWatchedContent - Get Top Watched Content
- enablePaperTrail - Enabling Papertrail
- logLine - Logging a single line message.
- logMultiLine - Logging a multi-line message
- getBannerImage - Get Banner Image
- getThumbImage - Get Thumb Image
- markPlayed - Mark Media Played
- markUnplayed - Mark Media Unplayed
- updatePlayProgress - Update Media Play Progress
- addPlaylistContents - Adding to a Playlist
- clearPlaylistContents - Delete Playlist Contents
- createPlaylist - Create a Playlist
- deletePlaylist - Deletes a Playlist
- getPlaylist - Retrieve Playlist
- getPlaylistContents - Retrieve Playlist Contents
- getPlaylists - Get All Playlists
- updatePlaylist - Update a Playlist
- uploadPlaylist - Upload Playlist
- getServerResources - Get Server Resources
- getCompanionsData - Get Companions Data
- getGeoData - Get Geo Data
- getHomeData - Get Plex Home Data
- getPin - Get a Pin
- getTokenByPinId - Get Access Token by PinId
- getUserFriends - Get list of friends of the user logged in
- getSearchResults - Get Search Results
- performSearch - Perform a search
- performVoiceSearch - Perform a voice search
- getMediaProviders - Get Media Providers
- getServerIdentity - Get Server Identity
- getAvailableClients - Get Available Clients
- getDevices - Get Devices
- getMyPlexAccount - Get MyPlex Account
- getResizedPhoto - Get a Resized Photo
- getServerCapabilities - Get Server Capabilities
- getServerList - Get Server List
- getServerPreferences - Get Server Preferences
- getSessionHistory - Get Session History
- getSessions - Get Active Sessions
- getTranscodeSessions - Get Transcode Sessions
- stopTranscodeSession - Stop a Transcode Session
- getBandwidthStatistics - Get Bandwidth Statistics
- getResourcesStatistics - Get Resources Statistics
- getStatistics - Get Media Statistics
- applyUpdates - Apply Updates
- checkForUpdates - Checking for updates
- getUpdateStatus - Querying status of updates
- getTimeline - Get the timeline for a media item
- startUniversalTranscode - Start Universal Transcode
- getWatchList - Get User Watchlist
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errors\SDKException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the getMediaProviders
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errors\GetMediaProvidersBadRequest | 400 | application/json |
Errors\GetMediaProvidersUnauthorized | 401 | application/json |
Errors\SDKException | 4XX, 5XX | */* |
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
$security = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()->setSecurity($security)->build();
try {
$response = $sdk->server->getMediaProviders(
xPlexToken: 'CV5xoxjTpFKUzBTShsaf'
);
if ($response->object !== null) {
// handle response
}
} catch (Errors\GetMediaProvidersBadRequestThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\GetMediaProvidersUnauthorizedThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\SDKException $e) {
// handle default exception
throw $e;
}
The default server {protocol}://{ip}:{port}
contains variables and is set to https://10.10.10.47:32400
by default. To override default values, the following builder methods are available when initializing the SDK client instance:
setProtocol(Plex_API\ServerProtocol protocol)
setIp(string ip)
setPort(string port)
The default server can also be overridden globally using the setServerUrl(string $serverUrl)
builder method when initializing the SDK client instance. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
$security = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()
->setServerURL('https://10.10.10.47:32400')
->setSecurity($security)->build();
$response = $sdk->server->getMediaProviders(
xPlexToken: 'CV5xoxjTpFKUzBTShsaf'
);
if ($response->object !== null) {
// handle response
}
The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Operations;
$security = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()->setSecurity($security)->build();
$response = $sdk->plex->getServerResources(
'https://plex.tv/api/v2',
clientID: '3381b62b-9ab7-4e37-827b-203e9809eb58',
includeHttps: Operations\IncludeHttps::Enable,
includeRelay: Operations\IncludeRelay::Enable,
includeIPv6: Operations\IncludeIPv6::Enable
);
if ($response->plexDevices !== null) {
// handle response
}
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!