LukeHagar.PlexAPI.SDK
0.19.1
dotnet add package LukeHagar.PlexAPI.SDK --version 0.19.1
NuGet\Install-Package LukeHagar.PlexAPI.SDK -Version 0.19.1
<PackageReference Include="LukeHagar.PlexAPI.SDK" Version="0.19.1" />
<PackageVersion Include="LukeHagar.PlexAPI.SDK" Version="0.19.1" />
<PackageReference Include="LukeHagar.PlexAPI.SDK" />
paket add LukeHagar.PlexAPI.SDK --version 0.19.1
#r "nuget: LukeHagar.PlexAPI.SDK, 0.19.1"
#:package LukeHagar.PlexAPI.SDK@0.19.1
#addin nuget:?package=LukeHagar.PlexAPI.SDK&version=0.19.1
#tool nuget:?package=LukeHagar.PlexAPI.SDK&version=0.19.1
LukeHagar.PlexAPI.SDK
SDK Example Usage
Example
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
using LukeHagar.PlexAPI.SDK.Models.Requests;
var sdk = new PlexAPI(
accepts: LukeHagar.PlexAPI.SDK.Models.Components.Accepts.ApplicationXml,
clientIdentifier: "abc123",
product: "Plex for Roku",
version: "2.4.1",
platform: "Roku",
platformVersion: "4.3 build 1057",
device: "Roku 3",
model: "4200X",
deviceVendor: "Roku",
deviceName: "Living Room TV",
marketplace: "googlePlay",
token: "<YOUR_API_KEY_HERE>"
);
StartTranscodeSessionRequest req = new StartTranscodeSessionRequest() {
TranscodeType = TranscodeType.Music,
Extension = Extension.Mpd,
AdvancedSubtitles = LukeHagar.PlexAPI.SDK.Models.Components.AdvancedSubtitles.Burn,
AudioBoost = 50,
AudioChannelCount = 5,
AutoAdjustQuality = BoolInt.One,
AutoAdjustSubtitle = BoolInt.One,
DirectPlay = BoolInt.One,
DirectStream = BoolInt.One,
DirectStreamAudio = BoolInt.One,
DisableResolutionRotation = BoolInt.One,
HasMDE = BoolInt.One,
Location = StartTranscodeSessionQueryParamLocation.Wan,
MediaBufferSize = 102400,
MediaIndex = 0,
MusicBitrate = 5000,
Offset = 90.5D,
PartIndex = 0,
Path = "/library/metadata/151671",
PeakBitrate = 12000,
PhotoResolution = "1080x1080",
Protocol = StartTranscodeSessionQueryParamProtocol.Dash,
SecondsPerSegment = 5,
SubtitleSize = 50,
VideoBitrate = 12000,
VideoQuality = 50,
VideoResolution = "1080x1080",
XPlexClientProfileExtra = "add-limitation(scope=videoCodec&scopeName=*&type=upperBound&name=video.frameRate&value=60&replace=true)+append-transcode-target-codec(type=videoProfile&context=streaming&videoCodec=h264%2Chevc&audioCodec=aac&protocol=dash)",
XPlexClientProfileName = "generic",
};
var res = await sdk.Transcoder.StartTranscodeSessionAsync(req);
// handle response
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|---|---|
Token |
apiKey | API key |
To authenticate with the API the Token parameter must be set when initializing the SDK client instance. For example:
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
using LukeHagar.PlexAPI.SDK.Models.Requests;
var sdk = new PlexAPI(
token: "<YOUR_API_KEY_HERE>",
accepts: LukeHagar.PlexAPI.SDK.Models.Components.Accepts.ApplicationXml,
clientIdentifier: "abc123",
product: "Plex for Roku",
version: "2.4.1",
platform: "Roku",
platformVersion: "4.3 build 1057",
device: "Roku 3",
model: "4200X",
deviceVendor: "Roku",
deviceName: "Living Room TV",
marketplace: "googlePlay"
);
GetServerInfoRequest req = new GetServerInfoRequest() {};
var res = await sdk.General.GetServerInfoAsync(req);
// handle response
Error Handling
PlexAPIError is the base exception class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
|---|---|---|
Message |
string | Error message |
StatusCode |
int | HTTP status code |
Headers |
HttpResponseHeaders | HTTP headers |
ContentType |
string? | HTTP content type |
RawResponse |
HttpResponseMessage | HTTP response object |
Body |
string | HTTP response body |
Example
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
using LukeHagar.PlexAPI.SDK.Models.Errors;
using LukeHagar.PlexAPI.SDK.Models.Requests;
var sdk = new PlexAPI(
accepts: LukeHagar.PlexAPI.SDK.Models.Components.Accepts.ApplicationXml,
clientIdentifier: "abc123",
product: "Plex for Roku",
version: "2.4.1",
platform: "Roku",
platformVersion: "4.3 build 1057",
device: "Roku 3",
model: "4200X",
deviceVendor: "Roku",
deviceName: "Living Room TV",
marketplace: "googlePlay",
token: "<YOUR_API_KEY_HERE>"
);
try
{
GetServerInfoRequest req = new GetServerInfoRequest() {};
var res = await sdk.General.GetServerInfoAsync(req);
// handle response
}
catch (PlexAPIError ex) // all SDK exceptions inherit from PlexAPIError
{
// ex.ToString() provides a detailed error message
System.Console.WriteLine(ex);
// Base exception fields
HttpResponseMessage rawResponse = ex.RawResponse;
HttpResponseHeaders headers = ex.Headers;
int statusCode = ex.StatusCode;
string? contentType = ex.ContentType;
var responseBody = ex.Body;
}
catch (System.Net.Http.HttpRequestException ex)
{
// Check ex.InnerException for Network connectivity errors
}
Error Classes
Primary exception:
PlexAPIError: The base class for HTTP error responses.
<details><summary>Less common exceptions (2)</summary>
System.Net.Http.HttpRequestException: Network connectivity error. For more details about the underlying cause, inspect theex.InnerException.Inheriting from
PlexAPIError:ResponseValidationError: Thrown when the response data could not be deserialized into the expected type. </details>
Server Selection
Select Server by Index
You can override the default server globally by passing a server index to the serverIndex: int optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
| # | Server | Variables | Description |
|---|---|---|---|
| 0 | https://{IP-description}.{identifier}.plex.direct:{port} |
identifier<br/>IP-description<br/>port |
|
| 1 | {protocol}://{host}:{port} |
protocol<br/>host<br/>port |
|
| 2 | https://{full_server_url} |
full_server_url |
If the selected server has variables, you may override its default values through the additional parameters made available in the SDK constructor:
| Variable | Parameter | Default | Description |
|---|---|---|---|
identifier |
identifier: string |
"0123456789abcdef0123456789abcdef" |
The unique identifier of this particular PMS |
IP-description |
ipDescription: string |
"1-2-3-4" |
A - separated string of the IPv4 or IPv6 address components |
port |
port: string |
"32400" |
The Port number configured on the PMS. Typically (32400). <br/>If using a reverse proxy, this would be the port number configured on the proxy.<br/> |
protocol |
protocol: string |
"http" |
The network protocol to use. Typically (http or https) |
host |
host: string |
"localhost" |
The Host of the PMS.<br/>If using on a local network, this is the internal IP address of the server hosting the PMS.<br/>If using on an external network, this is the external IP address for your network, and requires port forwarding.<br/>If using a reverse proxy, this would be the external DNS domain for your network, and requires the proxy handle port forwarding. <br/> |
full_server_url |
fullServerUrl: string |
"http://localhost:32400" |
The full manual URL to access the PMS |
Example
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Models.Components;
using LukeHagar.PlexAPI.SDK.Models.Requests;
var sdk = new PlexAPI(
serverIndex: 0,
identifier: "0123456789abcdef0123456789abcdef",
ipDescription: "1-2-3-4",
port: "32400",
accepts: LukeHagar.PlexAPI.SDK.Models.Components.Accepts.ApplicationXml,
clientIdentifier: "abc123",
product: "Plex for Roku",
version: "2.4.1",
platform: "Roku",
platformVersion: "4.3 build 1057",
device: "Roku 3",
model: "4200X",
deviceVendor: "Roku",
deviceName: "Living Room TV",
marketplace: "googlePlay",
token: "<YOUR_API_KEY_HERE>"
);
GetServerInfoRequest req = new GetServerInfoRequest() {};
var res = await sdk.General.GetServerInfoAsync(req);
// handle response
Override Server URL Per-Client
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;
using LukeHagar.PlexAPI.SDK.Models.Requests;
var sdk = new PlexAPI(
serverUrl: "https://http://localhost:32400",
accepts: LukeHagar.PlexAPI.SDK.Models.Components.Accepts.ApplicationXml,
clientIdentifier: "abc123",
product: "Plex for Roku",
version: "2.4.1",
platform: "Roku",
platformVersion: "4.3 build 1057",
device: "Roku 3",
model: "4200X",
deviceVendor: "Roku",
deviceName: "Living Room TV",
marketplace: "googlePlay",
token: "<YOUR_API_KEY_HERE>"
);
GetServerInfoRequest req = new GetServerInfoRequest() {};
var res = await sdk.General.GetServerInfoAsync(req);
// handle response
Custom HTTP Client
The C# SDK makes API calls using an ISpeakeasyHttpClient that wraps the native
HttpClient. This
client provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle
errors and response.
The ISpeakeasyHttpClient interface allows you to either use the default SpeakeasyHttpClient that comes with the SDK,
or provide your own custom implementation with customized configuration such as custom message handlers, timeouts,
connection pooling, and other HTTP client settings.
The following example shows how to create a custom HTTP client with request modification and error handling:
using LukeHagar.PlexAPI.SDK;
using LukeHagar.PlexAPI.SDK.Utils;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
// Create a custom HTTP client
public class CustomHttpClient : ISpeakeasyHttpClient
{
private readonly ISpeakeasyHttpClient _defaultClient;
public CustomHttpClient()
{
_defaultClient = new SpeakeasyHttpClient();
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
// Add custom header and timeout
request.Headers.Add("x-custom-header", "custom value");
request.Headers.Add("x-request-timeout", "30");
try
{
var response = await _defaultClient.SendAsync(request, cancellationToken);
// Log successful response
Console.WriteLine($"Request successful: {response.StatusCode}");
return response;
}
catch (Exception error)
{
// Log error
Console.WriteLine($"Request failed: {error.Message}");
throw;
}
}
public void Dispose()
{
_httpClient?.Dispose();
_defaultClient?.Dispose();
}
}
// Use the custom HTTP client with the SDK
var customHttpClient = new CustomHttpClient();
var sdk = new PlexAPI(client: customHttpClient);
<details> <summary>You can also provide a completely custom HTTP client with your own configuration:</summary>
using LukeHagar.PlexAPI.SDK.Utils;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
// Custom HTTP client with custom configuration
public class AdvancedHttpClient : ISpeakeasyHttpClient
{
private readonly HttpClient _httpClient;
public AdvancedHttpClient()
{
var handler = new HttpClientHandler()
{
MaxConnectionsPerServer = 10,
// ServerCertificateCustomValidationCallback = customCertValidation, // Custom SSL validation if needed
};
_httpClient = new HttpClient(handler)
{
Timeout = TimeSpan.FromSeconds(30)
};
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
return await _httpClient.SendAsync(request, cancellationToken ?? CancellationToken.None);
}
public void Dispose()
{
_httpClient?.Dispose();
}
}
var sdk = PlexAPI.Builder()
.WithClient(new AdvancedHttpClient())
.Build();
</details>
<details> <summary>For simple debugging, you can enable request/response logging by implementing a custom client:</summary>
public class LoggingHttpClient : ISpeakeasyHttpClient
{
private readonly ISpeakeasyHttpClient _innerClient;
public LoggingHttpClient(ISpeakeasyHttpClient innerClient = null)
{
_innerClient = innerClient ?? new SpeakeasyHttpClient();
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
// Log request
Console.WriteLine($"Sending {request.Method} request to {request.RequestUri}");
var response = await _innerClient.SendAsync(request, cancellationToken);
// Log response
Console.WriteLine($"Received {response.StatusCode} response");
return response;
}
public void Dispose() => _innerClient?.Dispose();
}
var sdk = new PlexAPI(client: new LoggingHttpClient());
</details>
The SDK also provides built-in hook support through the SDKConfiguration.Hooks system, which automatically handles
BeforeRequestAsync, AfterSuccessAsync, and AfterErrorAsync hooks for advanced request lifecycle management.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- newtonsoft.json (>= 13.0.3)
- nodatime (>= 3.1.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on LukeHagar.PlexAPI.SDK:
| Repository | Stars |
|---|---|
|
Reaparr/Reaparr
Plex downloader that brings content from any server to yours!
|
| Version | Downloads | Last Updated |
|---|---|---|
| 0.19.1 | 283 | 11/13/2025 |
| 0.19.0 | 198 | 11/6/2025 |
| 0.16.1 | 656 | 8/7/2025 |
| 0.16.0 | 368 | 8/6/2025 |
| 0.15.1 | 752 | 6/9/2025 |
| 0.15.0 | 358 | 6/4/2025 |
| 0.14.11 | 418 | 5/5/2025 |
| 0.14.10 | 424 | 5/1/2025 |
| 0.14.9 | 588 | 4/19/2025 |
| 0.14.7 | 478 | 4/14/2025 |
| 0.14.5 | 424 | 4/6/2025 |
| 0.14.4 | 472 | 4/3/2025 |
| 0.14.3 | 460 | 3/31/2025 |
| 0.14.2 | 483 | 3/9/2025 |
| 0.14.1 | 551 | 3/7/2025 |
| 0.14.0 | 480 | 2/10/2025 |
| 0.13.6 | 135 | 2/7/2025 |
| 0.13.5 | 160 | 2/6/2025 |
| 0.13.4 | 176 | 2/5/2025 |
| 0.13.3 | 261 | 1/27/2025 |
| 0.13.2 | 138 | 1/26/2025 |
| 0.13.1 | 143 | 1/26/2025 |
| 0.13.0 | 184 | 1/24/2025 |
| 0.12.1 | 210 | 12/22/2024 |
| 0.12.0 | 135 | 12/21/2024 |
| 0.11.1 | 178 | 11/14/2024 |
| 0.11.0 | 162 | 11/12/2024 |
| 0.10.0 | 1,981 | 10/3/2024 |
| 0.9.2 | 152 | 10/2/2024 |
| 0.9.1 | 157 | 10/2/2024 |
| 0.9.0 | 178 | 10/2/2024 |
| 0.8.7 | 154 | 9/30/2024 |
| 0.8.6 | 137 | 9/30/2024 |
| 0.8.5 | 161 | 9/30/2024 |
| 0.8.1 | 173 | 9/26/2024 |
| 0.8.0 | 151 | 9/25/2024 |
| 0.7.1 | 162 | 9/21/2024 |
| 0.7.0 | 158 | 9/21/2024 |
| 0.6.11 | 152 | 9/19/2024 |
| 0.6.10 | 191 | 9/16/2024 |
| 0.5.3 | 193 | 9/8/2024 |
| 0.4.2 | 160 | 8/31/2024 |
| 0.3.0 | 138 | 8/31/2024 |