speakeasybot 1e29008284 ## Java SDK Changes Detected:
* `plex-api.libraryPlaylists.addPlaylistItems()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.libraryPlaylists.clearPlaylistItems()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.libraryCollections.moveCollectionItem()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.libraryCollections.deleteCollectionItem()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.libraryCollections.addCollectionItems()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.content.getSonicallySimilar()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.butler.stopTask()`:  `request` **Changed** **Breaking** ⚠️
* `plex-api.butler.startTask()`:  `request` **Changed** **Breaking** ⚠️
* `plex-api.content.getSonicPath()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.downloadQueue.getItemDecision()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.hubs.getAllHubs()`: 
  *  `request.onlyTransient` **Changed**
  *  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.hubs.getContinueWatching()`:  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.hubs.getPromotedHubs()`:  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.hubs.getMetadataHubs()`: 
  *  `request.onlyTransient` **Changed**
  *  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.hubs.getPostplayHubs()`: 
  *  `request.onlyTransient` **Changed**
  *  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.hubs.getRelatedHubs()`: 
  *  `request.onlyTransient` **Changed**
  *  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.hubs.getSectionHubs()`: 
  *  `request.onlyTransient` **Changed**
  *  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.content.getAllLeaves()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.content.listContent()`: 
  *  `request` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.search.searchHubs()`:  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.content.getAlbums()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getLibraryItems()`: 
  *  `request.mediaQuery` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.ingestTransientItem()`: 
  *  `request` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getLibraryMatches()`: 
  *  `request` **Changed** **Breaking** ⚠️
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.content.getMetadataItem()`: 
  *  `request` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getSections()`:  `response.mediacontainer.directory.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.addSection()`: 
  *  `request` **Changed**
  *  `response.mediacontainer.directory.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getTags()`: 
  *  `request.type` **Changed** **Breaking** ⚠️
* `plex-api.content.getCollectionItems()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getAllItemLeaves()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.status.listSessions()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playQueue.movePlayQueueItem()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getExtras()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playQueue.deletePlayQueueItem()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playQueue.unshuffle()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.listMatches()`: 
  *  `request.manual` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.listSonicallySimilar()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playQueue.shuffle()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getRelatedItems()`:  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.listSimilar()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playQueue.resetPlayQueue()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getItemTree()`:  `response.mediacontainer.metadataItem.[]` **Changed** **Breaking** ⚠️
* `plex-api.playQueue.clearPlayQueue()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playQueue.addToPlayQueue()`: 
  *  `request.next` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getCommon()`: 
  *  `request.mediaQuery` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getPerson()`:  `response.mediacontainer.directory.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.listPersonMedia()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playQueue.getPlayQueue()`: 
  *  `request` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getLibraryDetails()`: 
  *  `request.includeDetails` **Changed**
  *  `response.mediacontainer.directory.[]` **Changed** **Breaking** ⚠️
* `plex-api.libraryPlaylists.movePlaylistItem()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.autocomplete()`: 
  *  `request.mediaQuery` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.library.getCollections()`: 
  *  `request.mediaQuery` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.libraryPlaylists.getPlaylistGeneratorItems()`:  `response.mediacontainer.metadata` **Changed** **Breaking** ⚠️
* `plex-api.libraryPlaylists.deletePlaylistItem()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.search.voiceSearchHubs()`: 
  *  `request.type` **Changed** **Breaking** ⚠️
  *  `response.mediacontainer.hub.[].metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.libraryPlaylists.createPlaylist()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playlist.getPlaylistItems()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playlist.getPlaylist()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.playlist.listPlaylists()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.collections.createCollection()`: 
  *  `request.type` **Changed** **Breaking** ⚠️
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.dvRs.tuneChannel()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.liveTv.getSessions()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.liveTv.getLiveTvSession()`:  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.transcoder.makeDecision()`: 
  *  `request` **Changed**
  *  `response.mediacontainer.metadata.[]` **Changed** **Breaking** ⚠️
* `plex-api.subscriptions.getAllSubscriptions()`: 
  *  `request` **Changed**
  *  `response.mediacontainer.mediaSubscription.[].mediaGrabOperation.[].metadata` **Changed** **Breaking** ⚠️
* `plex-api.subscriptions.createSubscription()`:  `response.mediacontainer.mediaSubscription.[].mediaGrabOperation.[].metadata` **Changed** **Breaking** ⚠️
* `plex-api.subscriptions.getScheduledRecordings()`:  `response.mediacontainer.mediaGrabOperation.[].metadata` **Changed** **Breaking** ⚠️
* `plex-api.subscriptions.getTemplate()`:  `response.mediacontainer.subscriptionTemplate.[].mediaSubscription.[].mediaGrabOperation.[].metadata` **Changed** **Breaking** ⚠️
* `plex-api.subscriptions.getSubscription()`: 
  *  `request` **Changed**
  *  `response.mediacontainer.mediaSubscription.[].mediaGrabOperation.[].metadata` **Changed** **Breaking** ⚠️
* `plex-api.subscriptions.editSubscriptionPreferences()`:  `response.mediacontainer.mediaSubscription.[].mediaGrabOperation.[].metadata` **Changed** **Breaking** ⚠️
* `plex-api.subscriptions.reorderSubscription()`:  `response.mediacontainer.mediaSubscription.[].mediaGrabOperation.[].metadata` **Changed** **Breaking** ⚠️
* `plex-api.library.addSubtitles()`:  `request` **Changed**
* `plex-api.libraryPlaylists.uploadPlaylist()`: 
  *  `request.force` **Changed**
* `plex-api.transcoder.transcodeSubtitles()`:  `request` **Changed**
* `plex-api.transcoder.startTranscodeSession()`:  `request` **Changed**
* `plex-api.library.getMediaPart()`: 
  *  `request.download` **Changed**
* `plex-api.library.detectIntros()`: 
  *  `request.force` **Changed**
* `plex-api.library.getSectionImage()`: 
  *  `request.mediaQuery` **Changed**
* `plex-api.library.deleteMediaItem()`: 
  *  `request.proxy` **Changed**
* `plex-api.library.refreshItemsMetadata()`: 
  *  `request.markUpdated` **Changed**
* `plex-api.authentication.postUsersSignInData()`: **Added**
* `plex-api.authentication.getTokenDetails()`: **Added**
* `plex-api.library.detectCredits()`:  `request` **Changed**
* `plex-api.library.setStreamSelection()`: 
  *  `request.allParts` **Changed**
* `plex-api.library.updateItems()`: 
  *  `request.field.locked` **Changed**
* `plex-api.playQueue.createPlayQueue()`:  `request` **Changed**
* `plex-api.library.deleteLibrarySection()`: 
  *  `request.async` **Changed**
* `plex-api.library.getAugmentationStatus()`: 
  *  `request.wait` **Changed**
* `plex-api.transcoder.transcodeImage()`:  `request` **Changed**
* `plex-api.devices.modifyDevice()`: 
  *  `request.enabled` **Changed**
* `plex-api.library.detectVoiceActivity()`:  `request` **Changed**
* `plex-api.library.getStream()`: 
  *  `request.autoAdjustSubtitle` **Changed**
* `plex-api.library.startBifGeneration()`: 
  *  `request.force` **Changed**
* `plex-api.library.getFirstCharacters()`: 
  *  `request.mediaQuery` **Changed**
* `plex-api.ultraBlur.getImage()`: 
  *  `request.noise` **Changed**
* `plex-api.library.generateThumbs()`: 
  *  `request.force` **Changed**
* `plex-api.updater.applyUpdates()`:  `request` **Changed**
* `plex-api.updater.checkUpdates()`: 
  *  `request.download` **Changed**
* `plex-api.library.deleteMetadataItem()`: 
  *  `request.proxy` **Changed**
* `plex-api.library.optimizeDatabase()`: 
  *  `request.async` **Changed**
* `plex-api.library.refreshSection()`: 
  *  `request.force` **Changed**
* `plex-api.hubs.updateHubVisibility()`:  `request` **Changed**
* `plex-api.hubs.createCustomHub()`:  `request` **Changed**
* `plex-api.downloadQueue.addDownloadQueueItems()`:  `request` **Changed**
* `plex-api.timeline.report()`:  `request` **Changed**
* `plex-api.general.getSourceConnectionInformation()`: 
  *  `request.refresh` **Changed**
* `plex-api.plex.getServerResources()`: **Added**
* `plex-api.users.getUsers()`: **Added**
2025-12-01 00:42:04 +00:00
2024-09-16 19:31:20 +00:00
2025-12-01 00:42:04 +00:00
2025-12-01 00:42:04 +00:00
2024-07-01 16:03:10 +00:00
2025-12-01 00:42:04 +00:00
2025-12-01 00:42:04 +00:00
2025-12-01 00:42:04 +00:00
2025-12-01 00:42:04 +00:00
2024-07-01 16:03:10 +00:00
2025-12-01 00:42:04 +00:00

plexapi

Summary

Table of Contents

SDK Installation

Getting started

JDK 11 or later is required.

The samples below show how a published SDK artifact is used:

Gradle:

implementation 'dev.plexapi:plexapi:0.22.1'

Maven:

<dependency>
    <groupId>dev.plexapi</groupId>
    <artifactId>plexapi</artifactId>
    <version>0.22.1</version>
</dependency>

How to build

After cloning the git repository to your file system you can build the SDK artifact from source to the build directory by running ./gradlew build on *nix systems or gradlew.bat on Windows systems.

If you wish to build from source and publish the SDK artifact to your local Maven repository (on your filesystem) then use the following command (after cloning the git repo locally):

On *nix:

./gradlew publishToMavenLocal -Pskip.signing

On Windows:

gradlew.bat publishToMavenLocal -Pskip.signing

SDK Example Usage

Example

package hello.world;

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.*;
import dev.plexapi.sdk.models.shared.*;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        PlexAPI sdk = PlexAPI.builder()
                .accepts(Accepts.APPLICATION_XML)
                .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(System.getenv().getOrDefault("TOKEN", ""))
            .build();

        StartTranscodeSessionRequest req = StartTranscodeSessionRequest.builder()
                .transcodeType(TranscodeType.MUSIC)
                .extension(Extension.MPD)
                .advancedSubtitles(AdvancedSubtitles.BURN)
                .audioBoost(50L)
                .audioChannelCount(5L)
                .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(102400L)
                .mediaIndex(0L)
                .musicBitrate(5000L)
                .offset(90.5)
                .partIndex(0L)
                .path("/library/metadata/151671")
                .peakBitrate(12000L)
                .photoResolution("1080x1080")
                .protocol(StartTranscodeSessionQueryParamProtocol.DASH)
                .secondsPerSegment(5L)
                .subtitleSize(50L)
                .videoBitrate(12000L)
                .videoQuality(50L)
                .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")
                .build();

        StartTranscodeSessionResponse res = sdk.transcoder().startTranscodeSession()
                .request(req)
                .call();

        if (res.responseStream().isPresent()) {
            // handle response
        }
    }
}

Asynchronous Call

An asynchronous SDK client is also available that returns a CompletableFuture<T>. See Asynchronous Support for more details on async benefits and reactive library integration.

package hello.world;

import dev.plexapi.sdk.AsyncPlexAPI;
import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.GetServerInfoRequest;
import dev.plexapi.sdk.models.operations.async.GetServerInfoResponse;
import dev.plexapi.sdk.models.shared.Accepts;
import java.util.concurrent.CompletableFuture;

public class Application {

    public static void main(String[] args) {

        AsyncPlexAPI sdk = PlexAPI.builder()
                .accepts(Accepts.APPLICATION_XML)
                .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(System.getenv().getOrDefault("TOKEN", ""))
            .build()
            .async();

        GetServerInfoRequest req = GetServerInfoRequest.builder()
                .build();

        CompletableFuture<GetServerInfoResponse> resFut = sdk.general().getServerInfo()
                .request(req)
                .call();

        resFut.thenAccept(res -> {
            if (res.mediaContainerWithDirectory().isPresent()) {
            // handle response
            }
        });
    }
}

Available Resources and Operations

Available methods

activities()

authentication()

butler()

collections()

content()

devices()

downloadQueue()

dvRs()

epg()

events()

general()

hubs()

library()

libraryCollections()

libraryPlaylists()

liveTV()

log()

  • writeLog - Logging a multi-line message to the Plex Media Server log
  • writeMessage - Logging a single-line message to the Plex Media Server log
  • enablePapertrail - Enabling Papertrail

playlist()

playQueue()

plex()

preferences()

provider()

rate()

search()

status()

subscriptions()

timeline()

transcoder()

ultraBlur()

updater()

users()

  • getUsers - Get list of all connected users

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.

By default, an API error will throw a models/errors/SDKError exception. 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 getTokenDetails method throws the following exceptions:

Error Type Status Code Content Type
models/errors/GetTokenDetailsBadRequest 400 application/json
models/errors/GetTokenDetailsUnauthorized 401 application/json
models/errors/SDKError 4XX, 5XX */*

Example

package hello.world;

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.errors.GetTokenDetailsBadRequest;
import dev.plexapi.sdk.models.errors.GetTokenDetailsUnauthorized;
import dev.plexapi.sdk.models.operations.GetTokenDetailsRequest;
import dev.plexapi.sdk.models.operations.GetTokenDetailsResponse;
import dev.plexapi.sdk.models.shared.Accepts;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws GetTokenDetailsBadRequest, GetTokenDetailsUnauthorized, Exception {

        PlexAPI sdk = PlexAPI.builder()
                .accepts(Accepts.APPLICATION_XML)
                .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(System.getenv().getOrDefault("TOKEN", ""))
            .build();

        GetTokenDetailsRequest req = GetTokenDetailsRequest.builder()
                .build();

        GetTokenDetailsResponse res = sdk.authentication().getTokenDetails()
                .request(req)
                .call();

        if (res.userPlexAccount().isPresent()) {
            // handle response
        }
    }
}

Server Selection

Select Server by Index

You can override the default server globally using the .serverIndex(int serverIdx) builder method 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
IP-description
port
1 {protocol}://{host}:{port} protocol
host
port
2 https://{full_server_url} full_server_url

If the selected server has variables, you may override its default values using the associated builder method(s):

Variable BuilderMethod Default Description
identifier identifier(String identifier) "0123456789abcdef0123456789abcdef" The unique identifier of this particular PMS
IP-description ipDescription(String ipDescription) "1-2-3-4" A - separated string of the IPv4 or IPv6 address components
port port(String port) "32400" The Port number configured on the PMS. Typically (32400).
If using a reverse proxy, this would be the port number configured on the proxy.
protocol protocol(String protocol) "http" The network protocol to use. Typically (http or https)
host host(String host) "localhost" The Host of the PMS.
If using on a local network, this is the internal IP address of the server hosting the PMS.
If using on an external network, this is the external IP address for your network, and requires port forwarding.
If using a reverse proxy, this would be the external DNS domain for your network, and requires the proxy handle port forwarding.
full_server_url fullServerUrl(String fullServerUrl) "http://localhost:32400" The full manual URL to access the PMS

Example

package hello.world;

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.GetServerInfoRequest;
import dev.plexapi.sdk.models.operations.GetServerInfoResponse;
import dev.plexapi.sdk.models.shared.Accepts;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        PlexAPI sdk = PlexAPI.builder()
                .serverIndex(1)
                .protocol("<value>")
                .host("electric-excess.name")
                .port("36393")
                .accepts(Accepts.APPLICATION_XML)
                .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(System.getenv().getOrDefault("TOKEN", ""))
            .build();

        GetServerInfoRequest req = GetServerInfoRequest.builder()
                .build();

        GetServerInfoResponse res = sdk.general().getServerInfo()
                .request(req)
                .call();

        if (res.mediaContainerWithDirectory().isPresent()) {
            // handle response
        }
    }
}

Override Server URL Per-Client

The default server can also be overridden globally using the .serverURL(String serverUrl) builder method when initializing the SDK client instance. For example:

package hello.world;

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.GetServerInfoRequest;
import dev.plexapi.sdk.models.operations.GetServerInfoResponse;
import dev.plexapi.sdk.models.shared.Accepts;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        PlexAPI sdk = PlexAPI.builder()
                .serverURL("https://http://localhost:32400")
                .accepts(Accepts.APPLICATION_XML)
                .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(System.getenv().getOrDefault("TOKEN", ""))
            .build();

        GetServerInfoRequest req = GetServerInfoRequest.builder()
                .build();

        GetServerInfoResponse res = sdk.general().getServerInfo()
                .request(req)
                .call();

        if (res.mediaContainerWithDirectory().isPresent()) {
            // 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:

package hello.world;

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.errors.GetTokenDetailsBadRequest;
import dev.plexapi.sdk.models.errors.GetTokenDetailsUnauthorized;
import dev.plexapi.sdk.models.operations.GetTokenDetailsRequest;
import dev.plexapi.sdk.models.operations.GetTokenDetailsResponse;
import dev.plexapi.sdk.models.shared.Accepts;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws GetTokenDetailsBadRequest, GetTokenDetailsUnauthorized, Exception {

        PlexAPI sdk = PlexAPI.builder()
                .accepts(Accepts.APPLICATION_XML)
                .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(System.getenv().getOrDefault("TOKEN", ""))
            .build();

        GetTokenDetailsRequest req = GetTokenDetailsRequest.builder()
                .build();

        GetTokenDetailsResponse res = sdk.authentication().getTokenDetails()
                .request(req)
                .serverURL("https://plex.tv/api/v2")
                .call();

        if (res.userPlexAccount().isPresent()) {
            // handle response
        }
    }
}

Asynchronous Support

The SDK provides comprehensive asynchronous support using Java's CompletableFuture<T> and Reactive Streams Publisher<T> APIs. This design makes no assumptions about your choice of reactive toolkit, allowing seamless integration with any reactive library.

Why Use Async?

Asynchronous operations provide several key benefits:

  • Non-blocking I/O: Your threads stay free for other work while operations are in flight
  • Better resource utilization: Handle more concurrent operations with fewer threads
  • Improved scalability: Build highly responsive applications that can handle thousands of concurrent requests
  • Reactive integration: Works seamlessly with reactive streams and backpressure handling
Reactive Library Integration

The SDK returns Reactive Streams Publisher<T> instances for operations dealing with streams involving multiple I/O interactions. We use Reactive Streams instead of JDK Flow API to provide broader compatibility with the reactive ecosystem, as most reactive libraries natively support Reactive Streams.

Why Reactive Streams over JDK Flow?

  • Broader ecosystem compatibility: Most reactive libraries (Project Reactor, RxJava, Akka Streams, etc.) natively support Reactive Streams
  • Industry standard: Reactive Streams is the de facto standard for reactive programming in Java
  • Better interoperability: Seamless integration without additional adapters for most use cases

Integration with Popular Libraries:

  • Project Reactor: Use Flux.from(publisher) to convert to Reactor types
  • RxJava: Use Flowable.fromPublisher(publisher) for RxJava integration
  • Akka Streams: Use Source.fromPublisher(publisher) for Akka Streams integration
  • Vert.x: Use ReadStream.fromPublisher(vertx, publisher) for Vert.x reactive streams
  • Mutiny: Use Multi.createFrom().publisher(publisher) for Quarkus Mutiny integration

For JDK Flow API Integration: If you need JDK Flow API compatibility (e.g., for Quarkus/Mutiny 2), you can use adapters:

// Convert Reactive Streams Publisher to Flow Publisher
Flow.Publisher<T> flowPublisher = FlowAdapters.toFlowPublisher(reactiveStreamsPublisher);

// Convert Flow Publisher to Reactive Streams Publisher
Publisher<T> reactiveStreamsPublisher = FlowAdapters.toPublisher(flowPublisher);

For standard single-response operations, the SDK returns CompletableFuture<T> for straightforward async execution.

Supported Operations

Async support is available for:

  • Server-sent Events: Stream real-time events with Reactive Streams Publisher<T>
  • JSONL Streaming: Process streaming JSON lines asynchronously
  • Pagination: Iterate through paginated results using callAsPublisher() and callAsPublisherUnwrapped()
  • File Uploads: Upload files asynchronously with progress tracking
  • File Downloads: Download files asynchronously with streaming support
  • Standard Operations: All regular API calls return CompletableFuture<T> for async execution

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:

package hello.world;

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.GetServerInfoRequest;
import dev.plexapi.sdk.models.operations.GetServerInfoResponse;
import dev.plexapi.sdk.models.shared.Accepts;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        PlexAPI sdk = PlexAPI.builder()
                .token(System.getenv().getOrDefault("TOKEN", ""))
                .accepts(Accepts.APPLICATION_XML)
                .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")
            .build();

        GetServerInfoRequest req = GetServerInfoRequest.builder()
                .build();

        GetServerInfoResponse res = sdk.general().getServerInfo()
                .request(req)
                .call();

        if (res.mediaContainerWithDirectory().isPresent()) {
            // handle response
        }
    }
}

Custom HTTP Client

The Java SDK makes API calls using an HTTPClient 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 HTTPClient 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 executors, SSL context, connection pools, and other HTTP client settings.

The interface provides synchronous (send) methods and asynchronous (sendAsync) methods. The sendAsync method is used to power the async SDK methods and returns a CompletableFuture<HttpResponse<Blob>> for non-blocking operations.

The following example shows how to add a custom header and handle errors:

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.utils.HTTPClient;
import dev.plexapi.sdk.utils.SpeakeasyHTTPClient;
import dev.plexapi.sdk.utils.Utils;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.io.InputStream;
import java.time.Duration;

public class Application {
    public static void main(String[] args) {
        // Create a custom HTTP client with hooks
        HTTPClient httpClient = new HTTPClient() {
            private final HTTPClient defaultClient = new SpeakeasyHTTPClient();
            
            @Override
            public HttpResponse<InputStream> send(HttpRequest request) throws IOException, URISyntaxException, InterruptedException {
                // Add custom header and timeout using Utils.copy()
                HttpRequest modifiedRequest = Utils.copy(request)
                    .header("x-custom-header", "custom value")
                    .timeout(Duration.ofSeconds(30))
                    .build();
                    
                try {
                    HttpResponse<InputStream> response = defaultClient.send(modifiedRequest);
                    // Log successful response
                    System.out.println("Request successful: " + response.statusCode());
                    return response;
                } catch (Exception error) {
                    // Log error
                    System.err.println("Request failed: " + error.getMessage());
                    throw error;
                }
            }
        };

        PlexAPI sdk = PlexAPI.builder()
            .client(httpClient)
            .build();
    }
}
Custom HTTP Client Configuration

You can also provide a completely custom HTTP client with your own configuration:

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.utils.HTTPClient;
import dev.plexapi.sdk.utils.Blob;
import dev.plexapi.sdk.utils.ResponseWithBody;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.io.InputStream;
import java.time.Duration;
import java.util.concurrent.Executors;
import java.util.concurrent.CompletableFuture;

public class Application {
    public static void main(String[] args) {
        // Custom HTTP client with custom configuration
        HTTPClient customHttpClient = new HTTPClient() {
            private final HttpClient client = HttpClient.newBuilder()
                .executor(Executors.newFixedThreadPool(10))
                .connectTimeout(Duration.ofSeconds(30))
                // .sslContext(customSslContext) // Add custom SSL context if needed
                .build();

            @Override
            public HttpResponse<InputStream> send(HttpRequest request) throws IOException, URISyntaxException, InterruptedException {
                return client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            }

            @Override
            public CompletableFuture<HttpResponse<Blob>> sendAsync(HttpRequest request) {
                // Convert response to HttpResponse<Blob> for async operations
                return client.sendAsync(request, HttpResponse.BodyHandlers.ofPublisher())
                    .thenApply(resp -> new ResponseWithBody<>(resp, Blob::from));
            }
        };

        PlexAPI sdk = PlexAPI.builder()
            .client(customHttpClient)
            .build();
    }
}

You can also enable debug logging on the default SpeakeasyHTTPClient:

import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.utils.SpeakeasyHTTPClient;

public class Application {
    public static void main(String[] args) {
        SpeakeasyHTTPClient httpClient = new SpeakeasyHTTPClient();
        httpClient.enableDebugLogging(true);

        PlexAPI sdk = PlexAPI.builder()
            .client(httpClient)
            .build();
    }
}

Debugging

Debug

You can setup your SDK to emit debug logs for SDK requests and responses.

For request and response logging (especially json bodies), call enableHTTPDebugLogging(boolean) on the SDK builder like so:

SDK.builder()
    .enableHTTPDebugLogging(true)
    .build();

Example output:

Sending request: http://localhost:35123/bearer#global GET
Request headers: {Accept=[application/json], Authorization=[******], Client-Level-Header=[added by client], Idempotency-Key=[some-key], x-speakeasy-user-agent=[speakeasy-sdk/java 0.0.1 internal 0.1.0 org.openapis.openapi]}
Received response: (GET http://localhost:35123/bearer#global) 200
Response headers: {access-control-allow-credentials=[true], access-control-allow-origin=[*], connection=[keep-alive], content-length=[50], content-type=[application/json], date=[Wed, 09 Apr 2025 01:43:29 GMT], server=[gunicorn/19.9.0]}
Response body:
{
  "authenticated": true, 
  "token": "global"
}

WARNING: This should only used for temporary debugging purposes. Leaving this option on in a production system could expose credentials/secrets in logs. Authorization headers are redacted by default and there is the ability to specify redacted header names via SpeakeasyHTTPClient.setRedactedHeaders.

NOTE: This is a convenience method that calls HTTPClient.enableDebugLogging(). The SpeakeasyHTTPClient honors this setting. If you are using a custom HTTP client, it is up to the custom client to honor this setting.

Another option is to set the System property -Djdk.httpclient.HttpClient.log=all. However, this second option does not log bodies.

Development

Maturity

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.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

SDK Created by Speakeasy

Description
No description provided
Readme 8 MiB
Languages
Java 100%