mirror of
https://github.com/LukeHagar/plexjava.git
synced 2025-12-06 04:20:46 +00:00
16 KiB
16 KiB
Plex
(plex())
Overview
API Calls that perform operations directly against https://Plex.tv
Available Operations
- getHomeData - Get Plex Home Data
- getPin - Get a Pin
- getToken - Get Access Token
getHomeData
Retrieves the home data for the authenticated user, including details like home ID, name, guest access information, and subscription status.
Example Usage
package hello.world;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.models.shared.Security;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) throws Exception {
try {
PlexAPI sdk = PlexAPI.builder()
.accessToken("<YOUR_API_KEY_HERE>")
.xPlexClientIdentifier("Postman")
.build();
GetHomeDataResponse res = sdk.plex().getHomeData()
.call();
if (res.object().isPresent()) {
// handle response
}
} catch (lukehagar.plexapi.plexapi.models.errors.GetHomeDataResponseBody e) {
// handle exception
throw e;
} catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
Response
lukehagar.plexapi.plexapi.models.operations.GetHomeDataResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| models/errors/GetHomeDataResponseBody | 401 | application/json |
| models/errors/SDKError | 4xx-5xx | */* |
getPin
Retrieve a Pin from Plex.tv for authentication flows
Example Usage
package hello.world;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) throws Exception {
try {
PlexAPI sdk = PlexAPI.builder()
.xPlexClientIdentifier("Postman")
.build();
GetPinResponse res = sdk.plex().getPin()
.strong(false)
.xPlexClientIdentifier("Postman")
.xPlexProduct("Postman")
.call();
if (res.object().isPresent()) {
// handle response
}
} catch (lukehagar.plexapi.plexapi.models.errors.GetPinResponseBody e) {
// handle exception
throw e;
} catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
strong |
Optional<? extends Boolean> | ➖ | Determines the kind of code returned by the API call Strong codes are used for Pin authentication flows Non-Strong codes are used for Plex.tv/link |
|
xPlexClientIdentifier |
Optional<? extends String> | ➖ | The unique identifier for the client application This is used to track the client application and its usage (UUID, serial number, or other number unique per device) |
Postman |
xPlexProduct |
String | ✔️ | Product name of the application shown in the list of devices |
Postman |
serverURL |
String | ➖ | An optional server URL to use. | http://localhost:8080 |
Response
lukehagar.plexapi.plexapi.models.operations.GetPinResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| models/errors/GetPinResponseBody | 400 | application/json |
| models/errors/SDKError | 4xx-5xx | */* |
getToken
Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
Example Usage
package hello.world;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Optional;
import lukehagar.plexapi.plexapi.PlexAPI;
import lukehagar.plexapi.plexapi.models.operations.*;
import lukehagar.plexapi.plexapi.models.shared.*;
import lukehagar.plexapi.plexapi.utils.EventStream;
import org.openapitools.jackson.nullable.JsonNullable;
import static java.util.Map.entry;
public class Application {
public static void main(String[] args) throws Exception {
try {
PlexAPI sdk = PlexAPI.builder()
.xPlexClientIdentifier("Postman")
.build();
GetTokenResponse res = sdk.plex().getToken()
.pinID("<value>")
.xPlexClientIdentifier("Postman")
.call();
if (res.object().isPresent()) {
// handle response
}
} catch (lukehagar.plexapi.plexapi.models.errors.GetTokenResponseBody e) {
// handle exception
throw e;
} catch (lukehagar.plexapi.plexapi.models.errors.SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
pinID |
String | ✔️ | The PinID to retrieve an access token for | |
xPlexClientIdentifier |
Optional<? extends String> | ➖ | The unique identifier for the client application This is used to track the client application and its usage (UUID, serial number, or other number unique per device) |
Postman |
serverURL |
String | ➖ | An optional server URL to use. | http://localhost:8080 |
Response
lukehagar.plexapi.plexapi.models.operations.GetTokenResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| models/errors/GetTokenResponseBody | 400 | application/json |
| models/errors/SDKError | 4xx-5xx | */* |