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.GetAlbums(ctx, operations.GetAlbumsRequest{
SectionID: 817133,
})
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.GetAlbumsRequest;
import dev.plexapi.sdk.models.operations.GetAlbumsResponse;
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();
GetAlbumsRequest req = GetAlbumsRequest.builder()
.sectionId(817133L)
.build();
GetAlbumsResponse res = sdk.content().getAlbums()
.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.getAlbums({
sectionId: 817133,
});
console.log(result);
}
run();curl --request GET \
--url https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/albums \
--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}/albums"
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}/albums', 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}/albums",
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}/albums")
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/artist-fanart.jpg",
"identifier": "com.plexapp.plugins.library",
"mediaTagPrefix": "/system/bundle/media/flags/",
"mediaTagVersion": 1680272530,
"Metadata": [
{
"addedAt": 1681152176,
"allowSync": true,
"art": "/library/metadata/251/art/1716801576",
"deletedAt": 1682628386,
"Genre": [
{
"tag": "Comedy/Spoken"
}
],
"guid": "plex://album/5d07c894403c640290c0e196",
"index": 1,
"key": "/library/metadata/265/children",
"leafCount": 12,
"librarySectionID": 3,
"librarySectionTitle": "Music",
"librarySectionUUID": "d7fd8c81-a345-4e68-8113-92f23cb47e70",
"loudnessAnalysisVersion": "2",
"originallyAvailableAt": "2014-07-15",
"parentGuid": "plex://artist/5d07bbfc403c6402904a60e7",
"parentKey": "/library/metadata/251",
"parentRatingKey": "251",
"parentThumb": "/library/metadata/251/thumb/1716801576",
"parentTitle": "“Weird Al” Yankovic",
"rating": 8,
"ratingKey": "265",
"studio": "RCA",
"summary": "Already accepted as a bona fide talent in the world of parody -- his musicianship, comedic timing, his pop-culture reference awareness, and his great wordplay are all well-documented -- the only thing that matters when it comes to \"Weird Al\" Yankovic albums is how inspired the king of novelty songs sounds on any given LP. On his 14th studio album, Mandatory Fun, the inspiration meter goes well into the red, something heard instantly as Iggy Azalea's electro-rap \"Fancy\" does a complete 180 thematically on the opening \"Handy,\" the song now heading toward the local home improvement store where the craftsmen vogue in their orange vests and blow sweet come-ons like \"I'll bring you up to code\" and \"My socket wrenches are second to none.\" Pharrell's \"Happy\" becomes \"Tacky\" and Al's amazing ability to follow an everyday poke (\"Wear my Ed Hardy shirt with fluorescent orange pants\") with something brainy and reserved (\"Got my new résumé, it's printed in Comic Sans\") surprises once more, but for end-to-end \"wows,\" it's his brilliant redo of Robin Thicke's \"Blurred Lines,\" now the smug and twerking \"Word Crimes,\" which gives copy editors, English professors, and grammar nerds a reason to hit the dancefloor (\"And listen up when I tell you this/I hope you never use quotation marks for emphasis!\"). Hardcore and hilarious musical moments start to happen when Imagine Dragons' \"Radioactive\" becomes \"Inactive,\" a singalong anthem for the sluggish and the slovenly (\"Near comatose, no exercise/Don't tag my toe, I'm still alive\") with a dubstep-rock bassline that sounds like Galactus burping. Better still is the every-Al-album pop-polka medley, this time called \"Now That's What I Call Polka!\" which polkas-up Daft Punk (\"Get Lucky\"), PSY (\"Gangnam Style\"), and Miley Cyrus (\"Wrecking Ball\"), and with more Spike Jones-styled sound effects than usual. As for the originals this time out, the \"you suck!\"-minded \"Sports Song\" will be unavoidable under Friday night lights once a teen gets hold of it, while the ranting and wonderfully weird \"First World Problems\" sounds more like the Pixies than anything the Pixies did in 2014. Wonders never cease on Mandatory Fun, and neither do the laughs. ~ David Jeffries",
"thumb": "/library/metadata/265/thumb/1715112705",
"title": "Mandatory Fun",
"type": "album",
"updatedAt": 1715112705,
"year": 2014
}
],
"mixedParents": true,
"nocache": true,
"size": 12,
"thumb": "/:/resources/artist.png",
"title1": "Music",
"title2": "By Album",
"viewGroup": "album"
}
}Set section albums
Get all albums in a music 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.GetAlbums(ctx, operations.GetAlbumsRequest{
SectionID: 817133,
})
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.GetAlbumsRequest;
import dev.plexapi.sdk.models.operations.GetAlbumsResponse;
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();
GetAlbumsRequest req = GetAlbumsRequest.builder()
.sectionId(817133L)
.build();
GetAlbumsResponse res = sdk.content().getAlbums()
.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.getAlbums({
sectionId: 817133,
});
console.log(result);
}
run();curl --request GET \
--url https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/{sectionId}/albums \
--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}/albums"
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}/albums', 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}/albums",
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}/albums")
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/artist-fanart.jpg",
"identifier": "com.plexapp.plugins.library",
"mediaTagPrefix": "/system/bundle/media/flags/",
"mediaTagVersion": 1680272530,
"Metadata": [
{
"addedAt": 1681152176,
"allowSync": true,
"art": "/library/metadata/251/art/1716801576",
"deletedAt": 1682628386,
"Genre": [
{
"tag": "Comedy/Spoken"
}
],
"guid": "plex://album/5d07c894403c640290c0e196",
"index": 1,
"key": "/library/metadata/265/children",
"leafCount": 12,
"librarySectionID": 3,
"librarySectionTitle": "Music",
"librarySectionUUID": "d7fd8c81-a345-4e68-8113-92f23cb47e70",
"loudnessAnalysisVersion": "2",
"originallyAvailableAt": "2014-07-15",
"parentGuid": "plex://artist/5d07bbfc403c6402904a60e7",
"parentKey": "/library/metadata/251",
"parentRatingKey": "251",
"parentThumb": "/library/metadata/251/thumb/1716801576",
"parentTitle": "“Weird Al” Yankovic",
"rating": 8,
"ratingKey": "265",
"studio": "RCA",
"summary": "Already accepted as a bona fide talent in the world of parody -- his musicianship, comedic timing, his pop-culture reference awareness, and his great wordplay are all well-documented -- the only thing that matters when it comes to \"Weird Al\" Yankovic albums is how inspired the king of novelty songs sounds on any given LP. On his 14th studio album, Mandatory Fun, the inspiration meter goes well into the red, something heard instantly as Iggy Azalea's electro-rap \"Fancy\" does a complete 180 thematically on the opening \"Handy,\" the song now heading toward the local home improvement store where the craftsmen vogue in their orange vests and blow sweet come-ons like \"I'll bring you up to code\" and \"My socket wrenches are second to none.\" Pharrell's \"Happy\" becomes \"Tacky\" and Al's amazing ability to follow an everyday poke (\"Wear my Ed Hardy shirt with fluorescent orange pants\") with something brainy and reserved (\"Got my new résumé, it's printed in Comic Sans\") surprises once more, but for end-to-end \"wows,\" it's his brilliant redo of Robin Thicke's \"Blurred Lines,\" now the smug and twerking \"Word Crimes,\" which gives copy editors, English professors, and grammar nerds a reason to hit the dancefloor (\"And listen up when I tell you this/I hope you never use quotation marks for emphasis!\"). Hardcore and hilarious musical moments start to happen when Imagine Dragons' \"Radioactive\" becomes \"Inactive,\" a singalong anthem for the sluggish and the slovenly (\"Near comatose, no exercise/Don't tag my toe, I'm still alive\") with a dubstep-rock bassline that sounds like Galactus burping. Better still is the every-Al-album pop-polka medley, this time called \"Now That's What I Call Polka!\" which polkas-up Daft Punk (\"Get Lucky\"), PSY (\"Gangnam Style\"), and Miley Cyrus (\"Wrecking Ball\"), and with more Spike Jones-styled sound effects than usual. As for the originals this time out, the \"you suck!\"-minded \"Sports Song\" will be unavoidable under Friday night lights once a teen gets hold of it, while the ranting and wonderfully weird \"First World Problems\" sounds more like the Pixies than anything the Pixies did in 2014. Wonders never cease on Mandatory Fun, and neither do the laughs. ~ David Jeffries",
"thumb": "/library/metadata/265/thumb/1715112705",
"title": "Mandatory Fun",
"type": "album",
"updatedAt": 1715112705,
"year": 2014
}
],
"mixedParents": true,
"nocache": true,
"size": 12,
"thumb": "/:/resources/artist.png",
"title1": "Music",
"title2": "By Album",
"viewGroup": "album"
}
}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?