package main
import(
"context"
"github.com/LukeHagar/plexgo"
"log"
)
func main() {
ctx := context.Background()
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Library.GetSections(ctx)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}package hello.world;
import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.GetSectionsResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
PlexAPI sdk = PlexAPI.builder()
.token(System.getenv().getOrDefault("TOKEN", ""))
.build();
GetSectionsResponse res = sdk.library().getSections()
.call();
if (res.object().isPresent()) {
// handle response
}
}
}import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
token: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await plexAPI.library.getSections();
console.log(result);
}
run();curl --request GET \
--url https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/all \
--header 'X-Plex-Token: <api-key>'import requests
url = "https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/all"
headers = {"X-Plex-Token": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-Plex-Token': '<api-key>'}};
fetch('https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/all', 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/all",
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-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/all")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Plex-Token"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"MediaContainer": {
"identifier": "<string>",
"offset": 123,
"size": 123,
"totalSize": 123,
"allowSync": true,
"Directory": [
{
"type": "movie",
"language": "<string>",
"uuid": "e69655a2-ef48-4aba-bb19-d3cc3401e7d6",
"title": "Movies",
"agent": "<string>",
"allowSync": true,
"art": "<string>",
"composite": "<string>",
"content": true,
"contentChangedAt": 1556281940,
"createdAt": 1556281940,
"directory": true,
"filters": true,
"hidden": true,
"key": "<string>",
"Location": [
{
"id": 123,
"path": "<unknown>"
}
],
"refreshing": true,
"scannedAt": 1556281940,
"scanner": "<string>",
"thumb": "<string>",
"updatedAt": 1556281940
}
],
"title1": "<string>"
}
}Get library sections (main Media Provider Only)
A library section (commonly referred to as just a library) is a collection of media. Libraries are typed, and depending on their type provide either a flat or a hierarchical view of the media. For example, a music library has an artist > albums > tracks structure, whereas a movie library is flat. Libraries have features beyond just being a collection of media; for starters, they include information about supported types, filters and sorts. This allows a client to provide a rich interface around the media (e.g. allow sorting movies by release year).
package main
import(
"context"
"github.com/LukeHagar/plexgo"
"log"
)
func main() {
ctx := context.Background()
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Library.GetSections(ctx)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}package hello.world;
import dev.plexapi.sdk.PlexAPI;
import dev.plexapi.sdk.models.operations.GetSectionsResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
PlexAPI sdk = PlexAPI.builder()
.token(System.getenv().getOrDefault("TOKEN", ""))
.build();
GetSectionsResponse res = sdk.library().getSections()
.call();
if (res.object().isPresent()) {
// handle response
}
}
}import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
token: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await plexAPI.library.getSections();
console.log(result);
}
run();curl --request GET \
--url https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/all \
--header 'X-Plex-Token: <api-key>'import requests
url = "https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/all"
headers = {"X-Plex-Token": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-Plex-Token': '<api-key>'}};
fetch('https://{IP-description}.{identifier}.plex.direct:{port}/library/sections/all', 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/all",
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-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/all")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Plex-Token"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"MediaContainer": {
"identifier": "<string>",
"offset": 123,
"size": 123,
"totalSize": 123,
"allowSync": true,
"Directory": [
{
"type": "movie",
"language": "<string>",
"uuid": "e69655a2-ef48-4aba-bb19-d3cc3401e7d6",
"title": "Movies",
"agent": "<string>",
"allowSync": true,
"art": "<string>",
"composite": "<string>",
"content": true,
"contentChangedAt": 1556281940,
"createdAt": 1556281940,
"directory": true,
"filters": true,
"hidden": true,
"key": "<string>",
"Location": [
{
"id": 123,
"path": "<unknown>"
}
],
"refreshing": true,
"scannedAt": 1556281940,
"scanner": "<string>",
"thumb": "<string>",
"updatedAt": 1556281940
}
],
"title1": "<string>"
}
}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
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?