mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 04:20:46 +00:00
* `PlexApi.LibraryPlaylists.AddPlaylistItems()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LibraryPlaylists.ClearPlaylistItems()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LibraryCollections.MoveCollectionItem()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LibraryCollections.DeleteCollectionItem()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LibraryCollections.AddCollectionItems()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Content.GetSonicallySimilar()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Butler.StopTask()`: `request` **Changed** **Breaking** ⚠️ * `PlexApi.Butler.StartTask()`: `request` **Changed** **Breaking** ⚠️ * `PlexApi.Content.GetSonicPath()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.DownloadQueue.GetItemDecision()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Hubs.GetAllHubs()`: * `request.OnlyTransient` **Changed** * `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Hubs.GetContinueWatching()`: `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Hubs.GetPromotedHubs()`: `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Hubs.GetMetadataHubs()`: * `request.OnlyTransient` **Changed** * `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Hubs.GetPostplayHubs()`: * `request.OnlyTransient` **Changed** * `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Hubs.GetRelatedHubs()`: * `request.OnlyTransient` **Changed** * `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Hubs.GetSectionHubs()`: * `request.OnlyTransient` **Changed** * `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Content.GetAllLeaves()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Content.ListContent()`: * `request` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Search.SearchHubs()`: `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Content.GetAlbums()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetLibraryItems()`: * `request.MediaQuery` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.IngestTransientItem()`: * `request` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetLibraryMatches()`: * `request` **Changed** **Breaking** ⚠️ * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Content.GetMetadataItem()`: * `request` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetSections()`: `response.mediaContainer.Directory.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.AddSection()`: * `request` **Changed** * `response.mediaContainer.Directory.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetTags()`: * `request.Type` **Changed** **Breaking** ⚠️ * `PlexApi.Content.GetCollectionItems()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetAllItemLeaves()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Status.ListSessions()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.PlayQueue.MovePlayQueueItem()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetExtras()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.PlayQueue.DeletePlayQueueItem()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.PlayQueue.Unshuffle()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.ListMatches()`: * `request.Manual` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.ListSonicallySimilar()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.PlayQueue.Shuffle()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetRelatedItems()`: `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.ListSimilar()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.PlayQueue.ResetPlayQueue()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetItemTree()`: `response.mediaContainer.MetadataItem.[]` **Changed** **Breaking** ⚠️ * `PlexApi.PlayQueue.ClearPlayQueue()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.PlayQueue.AddToPlayQueue()`: * `request.Next` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetCommon()`: * `request.MediaQuery` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetPerson()`: `response.mediaContainer.Directory.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.ListPersonMedia()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.PlayQueue.GetPlayQueue()`: * `request` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetLibraryDetails()`: * `request.IncludeDetails` **Changed** * `response.mediaContainer.Directory.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LibraryPlaylists.MovePlaylistItem()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.Autocomplete()`: * `request.MediaQuery` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Library.GetCollections()`: * `request.MediaQuery` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LibraryPlaylists.GetPlaylistGeneratorItems()`: `response.mediaContainer.Metadata` **Changed** **Breaking** ⚠️ * `PlexApi.LibraryPlaylists.DeletePlaylistItem()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Search.VoiceSearchHubs()`: * `request.Type` **Changed** **Breaking** ⚠️ * `response.mediaContainer.Hub.[].Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LibraryPlaylists.CreatePlaylist()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Playlist.GetPlaylistItems()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Playlist.GetPlaylist()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Playlist.ListPlaylists()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Collections.CreateCollection()`: * `request.Type` **Changed** **Breaking** ⚠️ * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.DvRs.TuneChannel()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LiveTv.GetSessions()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.LiveTv.GetLiveTvSession()`: `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Transcoder.MakeDecision()`: * `request` **Changed** * `response.mediaContainer.Metadata.[]` **Changed** **Breaking** ⚠️ * `PlexApi.Subscriptions.GetAllSubscriptions()`: * `request` **Changed** * `response.mediaContainer.MediaSubscription.[].MediaGrabOperation.[].Metadata` **Changed** **Breaking** ⚠️ * `PlexApi.Subscriptions.CreateSubscription()`: `response.mediaContainer.MediaSubscription.[].MediaGrabOperation.[].Metadata` **Changed** **Breaking** ⚠️ * `PlexApi.Subscriptions.GetScheduledRecordings()`: `response.mediaContainer.MediaGrabOperation.[].Metadata` **Changed** **Breaking** ⚠️ * `PlexApi.Subscriptions.GetTemplate()`: `response.mediaContainer.SubscriptionTemplate.[].MediaSubscription.[].MediaGrabOperation.[].Metadata` **Changed** **Breaking** ⚠️ * `PlexApi.Subscriptions.GetSubscription()`: * `request` **Changed** * `response.mediaContainer.MediaSubscription.[].MediaGrabOperation.[].Metadata` **Changed** **Breaking** ⚠️ * `PlexApi.Subscriptions.EditSubscriptionPreferences()`: `response.mediaContainer.MediaSubscription.[].MediaGrabOperation.[].Metadata` **Changed** **Breaking** ⚠️ * `PlexApi.Subscriptions.ReorderSubscription()`: `response.mediaContainer.MediaSubscription.[].MediaGrabOperation.[].Metadata` **Changed** **Breaking** ⚠️ * `PlexApi.Library.AddSubtitles()`: `request` **Changed** * `PlexApi.LibraryPlaylists.UploadPlaylist()`: * `request.Force` **Changed** * `PlexApi.Transcoder.TranscodeSubtitles()`: `request` **Changed** * `PlexApi.Transcoder.StartTranscodeSession()`: `request` **Changed** * `PlexApi.Library.GetMediaPart()`: * `request.Download` **Changed** * `PlexApi.Library.DetectIntros()`: * `request.Force` **Changed** * `PlexApi.Library.GetSectionImage()`: * `request.MediaQuery` **Changed** * `PlexApi.Library.DeleteMediaItem()`: * `request.Proxy` **Changed** * `PlexApi.Library.RefreshItemsMetadata()`: * `request.MarkUpdated` **Changed** * `PlexApi.Authentication.Post-Users-Sign-In-Data()`: **Added** * `PlexApi.Authentication.GetTokenDetails()`: **Added** * `PlexApi.Library.DetectCredits()`: `request` **Changed** * `PlexApi.Library.SetStreamSelection()`: * `request.AllParts` **Changed** * `PlexApi.Library.UpdateItems()`: * `request.Field.locked` **Changed** * `PlexApi.PlayQueue.CreatePlayQueue()`: `request` **Changed** * `PlexApi.Library.DeleteLibrarySection()`: * `request.Async` **Changed** * `PlexApi.Library.GetAugmentationStatus()`: * `request.Wait` **Changed** * `PlexApi.Transcoder.TranscodeImage()`: `request` **Changed** * `PlexApi.Devices.ModifyDevice()`: * `request.Enabled` **Changed** * `PlexApi.Library.DetectVoiceActivity()`: `request` **Changed** * `PlexApi.Library.GetStream()`: * `request.AutoAdjustSubtitle` **Changed** * `PlexApi.Library.StartBifGeneration()`: * `request.Force` **Changed** * `PlexApi.Library.GetFirstCharacters()`: * `request.MediaQuery` **Changed** * `PlexApi.UltraBlur.GetImage()`: * `request.Noise` **Changed** * `PlexApi.Library.GenerateThumbs()`: * `request.Force` **Changed** * `PlexApi.Updater.ApplyUpdates()`: `request` **Changed** * `PlexApi.Updater.CheckUpdates()`: * `request.Download` **Changed** * `PlexApi.Library.DeleteMetadataItem()`: * `request.Proxy` **Changed** * `PlexApi.Library.OptimizeDatabase()`: * `request.Async` **Changed** * `PlexApi.Library.RefreshSection()`: * `request.Force` **Changed** * `PlexApi.Hubs.UpdateHubVisibility()`: `request` **Changed** * `PlexApi.Hubs.CreateCustomHub()`: `request` **Changed** * `PlexApi.DownloadQueue.AddDownloadQueueItems()`: `request` **Changed** * `PlexApi.Timeline.Report()`: `request` **Changed** * `PlexApi.General.GetSourceConnectionInformation()`: * `request.Refresh` **Changed** * `PlexApi.Plex.Get-Server-Resources()`: **Added** * `PlexApi.Users.Get-Users()`: **Added**
478 lines
20 KiB
Markdown
478 lines
20 KiB
Markdown
# LukeHagar.PlexAPI.SDK
|
|
|
|
|
|
<!-- Start SDK Example Usage [usage] -->
|
|
## SDK Example Usage
|
|
|
|
### Example
|
|
|
|
```csharp
|
|
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.True,
|
|
AutoAdjustSubtitle = BoolInt.True,
|
|
DirectPlay = BoolInt.True,
|
|
DirectStream = BoolInt.True,
|
|
DirectStreamAudio = BoolInt.True,
|
|
DisableResolutionRotation = BoolInt.True,
|
|
HasMDE = BoolInt.True,
|
|
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
|
|
```
|
|
<!-- End SDK Example Usage [usage] -->
|
|
|
|
<!-- Start Authentication [security] -->
|
|
## 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:
|
|
```csharp
|
|
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
|
|
```
|
|
<!-- End Authentication [security] -->
|
|
|
|
<!-- Start Error Handling [errors] -->
|
|
## Error Handling
|
|
|
|
[`PlexAPIError`](./LukeHagar/PlexAPI/SDK/Models/Errors/PlexAPIError.cs) 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 |
|
|
|
|
Some exceptions in this SDK include an additional `Payload` field, which will contain deserialized custom error data when present. Possible exceptions are listed in the [Error Classes](#error-classes) section.
|
|
|
|
### Example
|
|
|
|
```csharp
|
|
using LukeHagar.PlexAPI.SDK;
|
|
using LukeHagar.PlexAPI.SDK.Models.Components;
|
|
using LukeHagar.PlexAPI.SDK.Models.Errors;
|
|
using LukeHagar.PlexAPI.SDK.Models.Requests;
|
|
using System.Collections.Generic;
|
|
|
|
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
|
|
{
|
|
GetTokenDetailsRequest req = new GetTokenDetailsRequest() {};
|
|
|
|
var res = await sdk.Authentication.GetTokenDetailsAsync(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;
|
|
|
|
if (ex is GetTokenDetailsBadRequest) // different exceptions may be thrown depending on the method
|
|
{
|
|
// Check error data fields
|
|
GetTokenDetailsBadRequestPayload payload = ex.Payload;
|
|
List<Errors> Errors = payload.Errors;
|
|
HttpResponseMessage RawResponse = payload.RawResponse;
|
|
}
|
|
|
|
// An underlying cause may be provided
|
|
if (ex.InnerException != null)
|
|
{
|
|
Exception cause = ex.InnerException;
|
|
}
|
|
}
|
|
catch (System.Net.Http.HttpRequestException ex)
|
|
{
|
|
// Check ex.InnerException for Network connectivity errors
|
|
}
|
|
```
|
|
|
|
### Error Classes
|
|
|
|
**Primary exception:**
|
|
* [`PlexAPIError`](./LukeHagar/PlexAPI/SDK/Models/Errors/PlexAPIError.cs): The base class for HTTP error responses.
|
|
|
|
<details><summary>Less common exceptions (9)</summary>
|
|
|
|
* [`System.Net.Http.HttpRequestException`](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestexception): Network connectivity error. For more details about the underlying cause, inspect the `ex.InnerException`.
|
|
|
|
* Inheriting from [`PlexAPIError`](./LukeHagar/PlexAPI/SDK/Models/Errors/PlexAPIError.cs):
|
|
* [`GetTokenDetailsBadRequest`](./LukeHagar/PlexAPI/SDK/Models/Errors/GetTokenDetailsBadRequest.cs): Bad Request - A parameter was not specified, or was specified incorrectly. Status code `400`. Applicable to 1 of 240 methods.*
|
|
* [`PostUsersSignInDataBadRequest`](./LukeHagar/PlexAPI/SDK/Models/Errors/PostUsersSignInDataBadRequest.cs): Bad Request - A parameter was not specified, or was specified incorrectly. Status code `400`. Applicable to 1 of 240 methods.*
|
|
* [`GetUsersBadRequest`](./LukeHagar/PlexAPI/SDK/Models/Errors/GetUsersBadRequest.cs): Bad Request - A parameter was not specified, or was specified incorrectly. Status code `400`. Applicable to 1 of 240 methods.*
|
|
* [`GetTokenDetailsUnauthorized`](./LukeHagar/PlexAPI/SDK/Models/Errors/GetTokenDetailsUnauthorized.cs): Unauthorized - Returned if the X-Plex-Token is missing from the header or query. Status code `401`. Applicable to 1 of 240 methods.*
|
|
* [`PostUsersSignInDataUnauthorized`](./LukeHagar/PlexAPI/SDK/Models/Errors/PostUsersSignInDataUnauthorized.cs): Unauthorized - Returned if the X-Plex-Token is missing from the header or query. Status code `401`. Applicable to 1 of 240 methods.*
|
|
* [`GetUsersUnauthorized`](./LukeHagar/PlexAPI/SDK/Models/Errors/GetUsersUnauthorized.cs): Unauthorized - Returned if the X-Plex-Token is missing from the header or query. Status code `401`. Applicable to 1 of 240 methods.*
|
|
* [`GetServerResourcesUnauthorized`](./LukeHagar/PlexAPI/SDK/Models/Errors/GetServerResourcesUnauthorized.cs): Unauthorized - Returned if the X-Plex-Token is missing from the header or query. Status code `401`. Applicable to 1 of 240 methods.*
|
|
* [`ResponseValidationError`](./LukeHagar/PlexAPI/SDK/Models/Errors/ResponseValidationError.cs): Thrown when the response data could not be deserialized into the expected type.
|
|
</details>
|
|
|
|
\* Refer to the [relevant documentation](#available-resources-and-operations) to determine whether an exception applies to a specific operation.
|
|
<!-- End Error Handling [errors] -->
|
|
|
|
<!-- Start Server Selection [server] -->
|
|
## 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
|
|
|
|
```csharp
|
|
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:
|
|
```csharp
|
|
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
|
|
```
|
|
|
|
### Override Server URL Per-Operation
|
|
|
|
The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:
|
|
```csharp
|
|
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>"
|
|
);
|
|
|
|
GetTokenDetailsRequest req = new GetTokenDetailsRequest() {};
|
|
|
|
var res = await sdk.Authentication.GetTokenDetailsAsync(
|
|
request: req,
|
|
serverUrl: "https://plex.tv/api/v2"
|
|
);
|
|
|
|
// handle response
|
|
```
|
|
<!-- End Server Selection [server] -->
|
|
|
|
<!-- Start Custom HTTP Client [http-client] -->
|
|
## Custom HTTP Client
|
|
|
|
The C# SDK makes API calls using an `ISpeakeasyHttpClient` that wraps the native
|
|
[HttpClient](https://docs.microsoft.com/en-us/dotnet/api/system.net.http.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:
|
|
|
|
```csharp
|
|
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>
|
|
|
|
```csharp
|
|
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>
|
|
|
|
```csharp
|
|
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.
|
|
<!-- End Custom HTTP Client [http-client] -->
|
|
|
|
<!-- Placeholder for Future Speakeasy SDK Sections --> |