declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Operations;
$sdk = Plex_API\PlexAPI::builder()
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$response = $sdk->plex->getServerResources(
clientID: '3381b62b-9ab7-4e37-827b-203e9809eb58',
includeHttps: Operations\IncludeHttps::Enable,
includeRelay: Operations\IncludeRelay::Enable,
includeIPv6: Operations\IncludeIPv6::Enable
);
if ($response->plexDevices !== null) {
// handle response
}require 'plex_ruby_sdk'
s = ::PlexRubySDK::PlexAPI.new(
security: Models::Shared::Security.new(
access_token: "<YOUR_API_KEY_HERE>",
),
)
res = s.plex.get_server_resources(client_id="3381b62b-9ab7-4e37-827b-203e9809eb58", include_https=Models::Operations::IncludeHttps::ENABLE, include_relay=Models::Operations::IncludeRelay::ENABLE, include_i_pv6=Models::Operations::IncludeIPv6::ENABLE)
if ! res.plex_devices.nil?
# handle response
endpackage main
import(
"context"
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := plexgo.New(
plexgo.WithAccepts(components.AcceptsApplicationXML),
plexgo.WithClientIdentifier("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Plex.GetServerResources(ctx, operations.GetServerResourcesRequest{
IncludeHTTPS: operations.IncludeHTTPSTrue.ToPointer(),
IncludeRelay: operations.IncludeRelayTrue.ToPointer(),
IncludeIPv6: operations.IncludeIPv6True.ToPointer(),
})
if err != nil {
log.Fatal(err)
}
if res.PlexDevices != nil {
// handle response
}
}package hello.world;
import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.errors.GetServerResourcesUnauthorized;
import dev.plexapi.sdk.models.operations.*;
import dev.plexapi.sdk.models.shared.Accepts;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws GetServerResourcesUnauthorized, Exception {
PlexAPI sdk = PlexAPI.builder()
.accepts(Accepts.APPLICATION_XML)
.clientIdentifier("abc123")
.token(System.getenv().getOrDefault("TOKEN", ""))
.build();
GetServerResourcesRequest req = GetServerResourcesRequest.builder()
.includeHttps(IncludeHttps.True)
.includeRelay(IncludeRelay.True)
.includeIPv6(IncludeIPv6.True)
.build();
GetServerResourcesResponse res = sdk.plex().getServerResources()
.request(req)
.call();
if (res.plexDevices().isPresent()) {
// handle response
}
}
}import { PlexAPI } from "@lukehagar/plexjs";
import { IncludeHttps, IncludeIPv6, IncludeRelay } from "@lukehagar/plexjs/models/operations";
import { Accepts } from "@lukehagar/plexjs/models/shared";
const plexAPI = new PlexAPI({
accepts: Accepts.ApplicationXml,
clientIdentifier: "3381b62b-9ab7-4e37-827b-203e9809eb58",
token: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await plexAPI.plex.getServerResources({
includeHttps: IncludeHttps.True,
includeRelay: IncludeRelay.True,
includeIPv6: IncludeIPv6.True,
});
console.log(result);
}
run();curl --request GET \
--url https://plex.tv/api/v2/resources \
--header 'X-Plex-Client-Identifier: <x-plex-client-identifier>' \
--header 'X-Plex-Token: <api-key>'import requests
url = "https://plex.tv/api/v2/resources"
headers = {
"X-Plex-Client-Identifier": "<x-plex-client-identifier>",
"X-Plex-Token": "<api-key>"
}
response = requests.get(url, headers=headers)
print(response.text)const options = {
method: 'GET',
headers: {
'X-Plex-Client-Identifier': '<x-plex-client-identifier>',
'X-Plex-Token': '<api-key>'
}
};
fetch('https://plex.tv/api/v2/resources', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));[
{
"name": "<string>",
"product": "<string>",
"productVersion": "<string>",
"platform": "<string>",
"platformVersion": "<string>",
"device": "<string>",
"clientIdentifier": "<string>",
"createdAt": "2019-06-24T11:38:02Z",
"lastSeenAt": "2019-06-24T11:38:02Z",
"provides": "<string>",
"ownerId": 123,
"sourceTitle": "<string>",
"publicAddress": "<string>",
"accessToken": "<string>",
"owned": true,
"home": true,
"synced": true,
"relay": true,
"presence": true,
"httpsRequired": true,
"publicAddressMatches": true,
"dnsRebindingProtection": true,
"natLoopbackSupported": true,
"connections": [
{
"protocol": "http",
"address": "<string>",
"port": 123,
"uri": "<string>",
"local": true,
"relay": true,
"IPv6": true
}
]
}
]{
"errors": [
{
"code": 1001,
"message": "User could not be authenticated",
"status": 401
}
]
}Get Server Resources
Get Plex server access tokens and server connections
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Operations;
$sdk = Plex_API\PlexAPI::builder()
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$response = $sdk->plex->getServerResources(
clientID: '3381b62b-9ab7-4e37-827b-203e9809eb58',
includeHttps: Operations\IncludeHttps::Enable,
includeRelay: Operations\IncludeRelay::Enable,
includeIPv6: Operations\IncludeIPv6::Enable
);
if ($response->plexDevices !== null) {
// handle response
}require 'plex_ruby_sdk'
s = ::PlexRubySDK::PlexAPI.new(
security: Models::Shared::Security.new(
access_token: "<YOUR_API_KEY_HERE>",
),
)
res = s.plex.get_server_resources(client_id="3381b62b-9ab7-4e37-827b-203e9809eb58", include_https=Models::Operations::IncludeHttps::ENABLE, include_relay=Models::Operations::IncludeRelay::ENABLE, include_i_pv6=Models::Operations::IncludeIPv6::ENABLE)
if ! res.plex_devices.nil?
# handle response
endpackage main
import(
"context"
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := plexgo.New(
plexgo.WithAccepts(components.AcceptsApplicationXML),
plexgo.WithClientIdentifier("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Plex.GetServerResources(ctx, operations.GetServerResourcesRequest{
IncludeHTTPS: operations.IncludeHTTPSTrue.ToPointer(),
IncludeRelay: operations.IncludeRelayTrue.ToPointer(),
IncludeIPv6: operations.IncludeIPv6True.ToPointer(),
})
if err != nil {
log.Fatal(err)
}
if res.PlexDevices != nil {
// handle response
}
}package hello.world;
import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.errors.GetServerResourcesUnauthorized;
import dev.plexapi.sdk.models.operations.*;
import dev.plexapi.sdk.models.shared.Accepts;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws GetServerResourcesUnauthorized, Exception {
PlexAPI sdk = PlexAPI.builder()
.accepts(Accepts.APPLICATION_XML)
.clientIdentifier("abc123")
.token(System.getenv().getOrDefault("TOKEN", ""))
.build();
GetServerResourcesRequest req = GetServerResourcesRequest.builder()
.includeHttps(IncludeHttps.True)
.includeRelay(IncludeRelay.True)
.includeIPv6(IncludeIPv6.True)
.build();
GetServerResourcesResponse res = sdk.plex().getServerResources()
.request(req)
.call();
if (res.plexDevices().isPresent()) {
// handle response
}
}
}import { PlexAPI } from "@lukehagar/plexjs";
import { IncludeHttps, IncludeIPv6, IncludeRelay } from "@lukehagar/plexjs/models/operations";
import { Accepts } from "@lukehagar/plexjs/models/shared";
const plexAPI = new PlexAPI({
accepts: Accepts.ApplicationXml,
clientIdentifier: "3381b62b-9ab7-4e37-827b-203e9809eb58",
token: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await plexAPI.plex.getServerResources({
includeHttps: IncludeHttps.True,
includeRelay: IncludeRelay.True,
includeIPv6: IncludeIPv6.True,
});
console.log(result);
}
run();curl --request GET \
--url https://plex.tv/api/v2/resources \
--header 'X-Plex-Client-Identifier: <x-plex-client-identifier>' \
--header 'X-Plex-Token: <api-key>'import requests
url = "https://plex.tv/api/v2/resources"
headers = {
"X-Plex-Client-Identifier": "<x-plex-client-identifier>",
"X-Plex-Token": "<api-key>"
}
response = requests.get(url, headers=headers)
print(response.text)const options = {
method: 'GET',
headers: {
'X-Plex-Client-Identifier': '<x-plex-client-identifier>',
'X-Plex-Token': '<api-key>'
}
};
fetch('https://plex.tv/api/v2/resources', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));[
{
"name": "<string>",
"product": "<string>",
"productVersion": "<string>",
"platform": "<string>",
"platformVersion": "<string>",
"device": "<string>",
"clientIdentifier": "<string>",
"createdAt": "2019-06-24T11:38:02Z",
"lastSeenAt": "2019-06-24T11:38:02Z",
"provides": "<string>",
"ownerId": 123,
"sourceTitle": "<string>",
"publicAddress": "<string>",
"accessToken": "<string>",
"owned": true,
"home": true,
"synced": true,
"relay": true,
"presence": true,
"httpsRequired": true,
"publicAddressMatches": true,
"dnsRebindingProtection": true,
"natLoopbackSupported": true,
"connections": [
{
"protocol": "http",
"address": "<string>",
"port": 123,
"uri": "<string>",
"local": true,
"relay": true,
"IPv6": true
}
]
}
]{
"errors": [
{
"code": 1001,
"message": "User could not be authenticated",
"status": 401
}
]
}Authorizations
The token which identifies the user accessing the PMS. This can be either:
- A traditional access token obtained from plex.tv
- A JWT token obtained through the JWT authentication flow
JWT tokens provide better security with:
- Short-lived tokens (7 days expiration)
- Public-key cryptography (ED25519)
- Better clock synchronization
- Individual device revocation capability
Headers
Indicates the client accepts the indicated media types
application/json, application/xml An opaque identifier unique to the client
"abc123"
Query Parameters
Include Https entries in the results
0, 1 1
Include Relay addresses in the results E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400
0, 1 1
Include IPv6 entries in the results
0, 1 1
Response
List of Plex Devices. This includes Plex hosted servers and clients
The time the device was created/registered
"2019-06-24T11:38:02Z"
The last time the device was seen
"2019-06-24T11:38:02Z"
ownerId is null when the device is owned by the token used to send the request
Show child attributes
Show child attributes
Was this page helpful?