To add the NuGet package to a .NET project:
dotnet add package LukeHagar.PlexAPI.SDK
To add a reference to a local instance of the SDK in a .NET project:
dotnet add reference LukeHagar/PlexAPI/SDK/LukeHagar.PlexAPI.SDK.csproj
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
var sdk = new PlexAPI(
accessToken: "<YOUR_API_KEY_HERE>",
clientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
clientName: "Plex for Roku",
clientVersion: "2.4.1",
platform: "Roku",
deviceNickname: "Roku 3"
);
var res = await sdk.Server.GetServerCapabilitiesAsync();
// handle response
Available methods
- GetServerActivities - Get Server Activities
- CancelServerActivities - Cancel Server Activities
- GetTransientToken - Get a Transient Token
- GetSourceConnectionInformation - Get Source Connection Information
- GetTokenDetails - Get Token Details
- PostUsersSignInData - Get User Sign In Data
- GetButlerTasks - Get Butler tasks
- StartAllTasks - Start all Butler tasks
- StopAllTasks - Stop all Butler tasks
- StartTask - Start a single Butler task
- StopTask - Stop a single Butler task
- GetGlobalHubs - Get Global Hubs
- GetRecentlyAdded - Get Recently Added
- GetLibraryHubs - Get library specific hubs
- GetFileHash - Get Hash Value
- GetRecentlyAddedLibrary - Get Recently Added
- GetAllLibraries - Get All Libraries
- GetLibraryDetails - Get Library Details
- DeleteLibrary - Delete Library Section
- GetLibraryItems - Get Library Items
- GetRefreshLibraryMetadata - Refresh Metadata Of The Library
- GetSearchLibrary - Search Library
- GetSearchAllLibraries - Search All Libraries
- GetMetaDataByRatingKey - Get Metadata by RatingKey
- GetMetadataChildren - Get Items Children
- GetTopWatchedContent - Get Top Watched Content
- GetOnDeck - Get On Deck
- LogLine - Logging a single line message.
- LogMultiLine - Logging a multi-line message
- EnablePaperTrail - Enabling Papertrail
- MarkPlayed - Mark Media Played
- MarkUnplayed - Mark Media Unplayed
- UpdatePlayProgress - Update Media Play Progress
- GetBannerImage - Get Banner Image
- GetThumbImage - Get Thumb Image
- CreatePlaylist - Create a Playlist
- GetPlaylists - Get All Playlists
- GetPlaylist - Retrieve Playlist
- DeletePlaylist - Deletes a Playlist
- UpdatePlaylist - Update a Playlist
- GetPlaylistContents - Retrieve Playlist Contents
- ClearPlaylistContents - Delete Playlist Contents
- AddPlaylistContents - Adding to a Playlist
- UploadPlaylist - Upload Playlist
- 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
- PerformSearch - Perform a search
- PerformVoiceSearch - Perform a voice search
- GetSearchResults - Get Search Results
- GetServerCapabilities - Get Server Capabilities
- GetServerPreferences - Get Server Preferences
- GetAvailableClients - Get Available Clients
- GetDevices - Get Devices
- GetServerIdentity - Get Server Identity
- GetMyPlexAccount - Get MyPlex Account
- GetResizedPhoto - Get a Resized Photo
- GetMediaProviders - Get Media Providers
- GetServerList - Get Server List
- GetSessions - Get Active Sessions
- GetSessionHistory - Get Session History
- GetTranscodeSessions - Get Transcode Sessions
- StopTranscodeSession - Stop a Transcode Session
- GetStatistics - Get Media Statistics
- GetResourcesStatistics - Get Resources Statistics
- GetBandwidthStatistics - Get Bandwidth Statistics
- GetUpdateStatus - Querying status of updates
- CheckForUpdates - Checking for updates
- ApplyUpdates - Apply Updates
- GetTimeline - Get the timeline for a media item
- StartUniversalTranscode - Start Universal Transcode
- GetWatchList - Get User Watchlist
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 parameters are available when initializing the SDK client instance:
protocol: ServerProtocol
ip: string
port: string
The default server can also be overridden globally by passing a URL to the serverUrl: string
optional parameter when initializing the SDK client instance. For example:
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
var sdk = new PlexAPI(
serverUrl: "https://10.10.10.47:32400",
accessToken: "<YOUR_API_KEY_HERE>",
clientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
clientName: "Plex for Roku",
clientVersion: "2.4.1",
platform: "Roku",
deviceNickname: "Roku 3"
);
var res = await sdk.Server.GetServerCapabilitiesAsync();
// 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:
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
var sdk = new PlexAPI(
accessToken: "<YOUR_API_KEY_HERE>",
clientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
clientName: "Plex for Roku",
clientVersion: "2.4.1",
platform: "Roku",
deviceNickname: "Roku 3"
);
var res = await sdk.Plex.GetCompanionsDataAsync(serverUrl: "https://plex.tv/api/v2");
// handle response
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
AccessToken |
apiKey | API key |
To authenticate with the API the AccessToken
parameter must be set when initializing the SDK client instance. For example:
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
var sdk = new PlexAPI(
accessToken: "<YOUR_API_KEY_HERE>",
clientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
clientName: "Plex for Roku",
clientVersion: "2.4.1",
platform: "Roku",
deviceNickname: "Roku 3"
);
var res = await sdk.Server.GetServerCapabilitiesAsync();
// handle response
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 LukeHagar.PlexAPI.SDK.Models.Errors.SDKException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
Message |
string | The error message |
StatusCode |
int | The HTTP status code |
RawResponse |
HttpResponseMessage | 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 exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the GetServerCapabilitiesAsync
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
LukeHagar.PlexAPI.SDK.Models.Errors.GetServerCapabilitiesBadRequest | 400 | application/json |
LukeHagar.PlexAPI.SDK.Models.Errors.GetServerCapabilitiesUnauthorized | 401 | application/json |
LukeHagar.PlexAPI.SDK.Models.Errors.SDKException | 4XX, 5XX | */* |
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
using System;
using LukeHagar.PlexAPI.SDK.Models.Errors;
var sdk = new PlexAPI(
accessToken: "<YOUR_API_KEY_HERE>",
clientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
clientName: "Plex for Roku",
clientVersion: "2.4.1",
platform: "Roku",
deviceNickname: "Roku 3"
);
try
{
var res = await sdk.Server.GetServerCapabilitiesAsync();
// handle response
}
catch (Exception ex)
{
if (ex is GetServerCapabilitiesBadRequest)
{
// Handle exception data
throw;
}
else if (ex is GetServerCapabilitiesUnauthorized)
{
// Handle exception data
throw;
}
else if (ex is LukeHagar.PlexAPI.SDK.Models.Errors.SDKException)
{
// Handle default exception
throw;
}
}
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 | - |
- SDK Installation
- SDK Example Usage
- Available Resources and Operations
- Error Handling
- Server Selection
- Authentication
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!