package 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("abc123"),
plexgo.WithProduct("Plex for Roku"),
plexgo.WithVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithPlatformVersion("4.3 build 1057"),
plexgo.WithDevice("Roku 3"),
plexgo.WithModel("4200X"),
plexgo.WithDeviceVendor("Roku"),
plexgo.WithDeviceName("Living Room TV"),
plexgo.WithMarketplace("googlePlay"),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Content.GetAllLeaves(ctx, operations.GetAllLeavesRequest{
SectionID: 633197,
})
if err != nil {
log.Fatal(err)
}
if res.MediaContainerWithMetadata != nil {
// handle response
}
}package hello.world;
import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.GetAllLeavesRequest;
import dev.plexapi.sdk.models.operations.GetAllLeavesResponse;
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()
.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();
GetAllLeavesRequest req = GetAllLeavesRequest.builder()
.sectionId(633197L)
.build();
GetAllLeavesResponse res = sdk.content().getAllLeaves()
.request(req)
.call();
if (res.mediaContainerWithMetadata().isPresent()) {
// handle response
}
}
}import { PlexAPI } from "@lukehagar/plexjs";
import { Accepts } from "@lukehagar/plexjs/models/shared";
const plexAPI = new PlexAPI({
accepts: 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>",
});
async function run() {
const result = await plexAPI.content.getAllLeaves({
sectionId: 633197,
});
console.log(result);
}
run();curl --request GET \
--url https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves \
--header 'X-Plex-Client-Identifier: <x-plex-client-identifier>' \
--header 'X-Plex-Token: <api-key>'import requests
url = "https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves"
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://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "62437",
CURLOPT_URL => "https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Plex-Client-Identifier: <x-plex-client-identifier>",
"X-Plex-Token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Plex-Client-Identifier"] = '<x-plex-client-identifier>'
request["X-Plex-Token"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"MediaContainer": {
"content": "secondary",
"allowSync": false,
"art": "/:/resources/show-fanart.jpg",
"identifier": "com.plexapp.plugins.library",
"mediaTagPrefix": "/system/bundle/media/flags/",
"mediaTagVersion": 1680272530,
"Metadata": [
{
"addedAt": 1348327790,
"art": "/library/metadata/148/art/1715112830",
"audienceRating": 7.7,
"audienceRatingImage": "themoviedb://image.rating",
"chapterSource": "media",
"contentRating": "TV-PG",
"Director": [
{
"tag": "Stephen Furst"
}
],
"duration": 2625089,
"grandparentArt": "/library/metadata/148/art/1715112830",
"grandparentGuid": "plex://show/5d9c087202391c001f58a287",
"grandparentKey": "/library/metadata/148",
"grandparentRatingKey": "148",
"grandparentSlug": "babylon-5",
"grandparentTheme": "/library/metadata/148/theme/1715112830",
"grandparentThumb": "/library/metadata/148/thumb/1715112830",
"grandparentTitle": "Babylon 5",
"guid": "plex://episode/5d9c1359e264b7001fcb529c",
"index": 8,
"key": "/library/metadata/150",
"lastViewedAt": 1612468663,
"Media": [
{
"aspectRatio": 1.78,
"audioChannels": 6,
"audioCodec": "ac3",
"bitrate": 5741,
"container": "mkv",
"duration": 2625089,
"height": 480,
"id": 376,
"Part": [
{
"container": "mkv",
"duration": 2625089,
"file": "/Volumes/Media/TV Shows/Babylon 5/Season 4/Babylon 5 S04E08 The Illusion of Truth.mkv",
"id": 872,
"key": "/library/parts/872/1348327790/file.mkv",
"size": 1883816967,
"videoProfile": "main"
}
],
"videoCodec": "mpeg2video",
"videoFrameRate": "NTSC",
"videoProfile": "main",
"videoResolution": "480",
"width": 720
}
],
"originallyAvailableAt": "1997-02-17",
"parentGuid": "plex://season/602e691b66dfdb002c0a5034",
"parentIndex": 4,
"parentKey": "/library/metadata/149",
"parentRatingKey": "149",
"parentThumb": "/library/metadata/149/thumb/1681152133",
"parentTitle": "Season 4",
"ratingKey": "150",
"Role": [
{
"tag": "Hank Delgado"
},
{
"tag": "Diana Morgan"
},
{
"tag": "Jeff Griggs"
}
],
"summary": "A team of ISN reporters arrives at the station wanting to do a story about Babylon 5. Sheridan refuses at first, but finally agrees on the theory that at least a small part of their side of the conflict will be shown.",
"thumb": "/library/metadata/150/thumb/1681283788",
"title": "The Illusion of Truth",
"titleSort": "Illusion of Truth",
"type": "episode",
"updatedAt": 1681283788,
"viewCount": 1,
"Writer": [
{
"tag": "J. Michael Straczynski"
}
],
"year": 1997
}
],
"nocache": true,
"size": 41,
"thumb": "/:/resources/show.png",
"title1": "TV Shows",
"viewGroup": "show"
}
}Set section leaves
Get all leaves in a section (such as episodes in a show section)
package 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("abc123"),
plexgo.WithProduct("Plex for Roku"),
plexgo.WithVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithPlatformVersion("4.3 build 1057"),
plexgo.WithDevice("Roku 3"),
plexgo.WithModel("4200X"),
plexgo.WithDeviceVendor("Roku"),
plexgo.WithDeviceName("Living Room TV"),
plexgo.WithMarketplace("googlePlay"),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Content.GetAllLeaves(ctx, operations.GetAllLeavesRequest{
SectionID: 633197,
})
if err != nil {
log.Fatal(err)
}
if res.MediaContainerWithMetadata != nil {
// handle response
}
}package hello.world;
import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.GetAllLeavesRequest;
import dev.plexapi.sdk.models.operations.GetAllLeavesResponse;
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()
.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();
GetAllLeavesRequest req = GetAllLeavesRequest.builder()
.sectionId(633197L)
.build();
GetAllLeavesResponse res = sdk.content().getAllLeaves()
.request(req)
.call();
if (res.mediaContainerWithMetadata().isPresent()) {
// handle response
}
}
}import { PlexAPI } from "@lukehagar/plexjs";
import { Accepts } from "@lukehagar/plexjs/models/shared";
const plexAPI = new PlexAPI({
accepts: 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>",
});
async function run() {
const result = await plexAPI.content.getAllLeaves({
sectionId: 633197,
});
console.log(result);
}
run();curl --request GET \
--url https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves \
--header 'X-Plex-Client-Identifier: <x-plex-client-identifier>' \
--header 'X-Plex-Token: <api-key>'import requests
url = "https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves"
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://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "62437",
CURLOPT_URL => "https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Plex-Client-Identifier: <x-plex-client-identifier>",
"X-Plex-Token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/allLeaves")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Plex-Client-Identifier"] = '<x-plex-client-identifier>'
request["X-Plex-Token"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"MediaContainer": {
"content": "secondary",
"allowSync": false,
"art": "/:/resources/show-fanart.jpg",
"identifier": "com.plexapp.plugins.library",
"mediaTagPrefix": "/system/bundle/media/flags/",
"mediaTagVersion": 1680272530,
"Metadata": [
{
"addedAt": 1348327790,
"art": "/library/metadata/148/art/1715112830",
"audienceRating": 7.7,
"audienceRatingImage": "themoviedb://image.rating",
"chapterSource": "media",
"contentRating": "TV-PG",
"Director": [
{
"tag": "Stephen Furst"
}
],
"duration": 2625089,
"grandparentArt": "/library/metadata/148/art/1715112830",
"grandparentGuid": "plex://show/5d9c087202391c001f58a287",
"grandparentKey": "/library/metadata/148",
"grandparentRatingKey": "148",
"grandparentSlug": "babylon-5",
"grandparentTheme": "/library/metadata/148/theme/1715112830",
"grandparentThumb": "/library/metadata/148/thumb/1715112830",
"grandparentTitle": "Babylon 5",
"guid": "plex://episode/5d9c1359e264b7001fcb529c",
"index": 8,
"key": "/library/metadata/150",
"lastViewedAt": 1612468663,
"Media": [
{
"aspectRatio": 1.78,
"audioChannels": 6,
"audioCodec": "ac3",
"bitrate": 5741,
"container": "mkv",
"duration": 2625089,
"height": 480,
"id": 376,
"Part": [
{
"container": "mkv",
"duration": 2625089,
"file": "/Volumes/Media/TV Shows/Babylon 5/Season 4/Babylon 5 S04E08 The Illusion of Truth.mkv",
"id": 872,
"key": "/library/parts/872/1348327790/file.mkv",
"size": 1883816967,
"videoProfile": "main"
}
],
"videoCodec": "mpeg2video",
"videoFrameRate": "NTSC",
"videoProfile": "main",
"videoResolution": "480",
"width": 720
}
],
"originallyAvailableAt": "1997-02-17",
"parentGuid": "plex://season/602e691b66dfdb002c0a5034",
"parentIndex": 4,
"parentKey": "/library/metadata/149",
"parentRatingKey": "149",
"parentThumb": "/library/metadata/149/thumb/1681152133",
"parentTitle": "Season 4",
"ratingKey": "150",
"Role": [
{
"tag": "Hank Delgado"
},
{
"tag": "Diana Morgan"
},
{
"tag": "Jeff Griggs"
}
],
"summary": "A team of ISN reporters arrives at the station wanting to do a story about Babylon 5. Sheridan refuses at first, but finally agrees on the theory that at least a small part of their side of the conflict will be shown.",
"thumb": "/library/metadata/150/thumb/1681283788",
"title": "The Illusion of Truth",
"titleSort": "Illusion of Truth",
"type": "episode",
"updatedAt": 1681283788,
"viewCount": 1,
"Writer": [
{
"tag": "J. Michael Straczynski"
}
],
"year": 1997
}
],
"nocache": true,
"size": 41,
"thumb": "/:/resources/show.png",
"title1": "TV Shows",
"viewGroup": "show"
}
}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"
The name of the client product
"Plex for Roku"
The version of the client application
"2.4.1"
The platform of the client
"Roku"
The version of the platform
"4.3 build 1057"
A relatively friendly name for the client device
"Roku 3"
A potentially less friendly identifier for the device model
"4200X"
The device vendor
"Roku"
A friendly name for the client
"Living Room TV"
The marketplace on which the client application is distributed
"googlePlay"
Path Parameters
Section identifier
Response
OK
MediaContainer is the root element of most Plex API responses. It serves as a generic container for various types of content (Metadata, Hubs, Directories, etc.) and includes pagination information (offset, size, totalSize) when applicable.
Common attributes: - identifier: Unique identifier for this container - size: Number of items in this response page - totalSize: Total number of items available (for pagination) - offset: Starting index of this page (for pagination)
The container often "hoists" common attributes from its children. For example, if all tracks in a container share the same album title, the parentTitle attribute may appear on the MediaContainer rather than being repeated on each track.
Show child attributes
Show child attributes
Was this page helpful?