Get Session History

Plex stores information about the media play sessions for both videos and music tracks. This API command will return the information about each of those play sessions.

URL

GET http://{ip_address}:32400/status/sessions/history/all?X-Plex-Token={plex_token}

Parameters

NameDescription
ip_addressThe IP address of the Plex Media server.
plex_tokenThe Plex token.

Return Status

HTTP CodeDescription
200Success - The request was successful.
401Unauthorized - The Plex token provided was not valid.

Response

XML string value that lists all media being played from the Plex server. An example of the XML returned from the request is shown below for a video being transcoded:

<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="3693">
<Video historyKey="/status/sessions/history/1" key="/library/metadata/218860" ratingKey="218860" librarySectionID="2" title="Captain America: The Winter Soldier" type="movie" thumb="/library/metadata/218860/thumb/-1" viewedAt="1419652344" accountID="1" />
<Video historyKey="/status/sessions/history/2" key="/library/metadata/917" ratingKey="917" librarySectionID="4" parentKey="/library/metadata/916" grandparentKey="/library/metadata/871" title="At the Garbage Dump" grandparentTitle="Mighty Machines" type="episode" thumb="/library/metadata/917/thumb/-1" parentThumb="/library/metadata/916/thumb/1659190874" grandparentThumb="/library/metadata/871/thumb/1668149194" grandparentArt="/library/metadata/871/art/1668149194" index="7" parentIndex="1" originallyAvailableAt="1998-01-25" viewedAt="1419652401" accountID="1" />
<Video historyKey="/status/sessions/history/3" librarySectionID="2" title="Pixar Short Films Collection 1" type="movie" viewedAt="1419653678" accountID="1" />
<Video historyKey="/status/sessions/history/4" librarySectionID="2" title="Thomas and Friends Best of Percy" type="movie" viewedAt="1419653704" accountID="1" />
<Video historyKey="/status/sessions/history/5" librarySectionID="2" title="Thomas and Friends Best of Percy" type="movie" viewedAt="1419653743" accountID="1" />
<Video historyKey="/status/sessions/history/6" librarySectionID="2" title="Thomas and Friends Best of Percy" type="movie" viewedAt="1419653743" accountID="1" />
<Video historyKey="/status/sessions/history/7" librarySectionID="2" title="Thomas and Friends Best of Percy" type="movie" viewedAt="1419653744" accountID="1" />
<Video historyKey="/status/sessions/history/8" librarySectionID="2" title="Thomas and Friends Best of Percy" type="movie" viewedAt="1419653744" accountID="1" />
...
</MediaContainer>

The XML returned provides a list of all the play session history on the Plex server. The root is the MediaContainer element. This element contains one attribute that provides a count of the number of items in the session history.

MediaContainer Attributes
AttributeDescription
sizeThe number of sessions history.

Within the MediaContainer element are one or more Video elements. Each Video element represent the playing of one video at a point in time.

The attributes within a Video element is dependent on the type of video that was played.

Video Attributes
AttributeDescription
historyKeyThe unique identifier the history record.
keyThe relative URL of the video information.
ratingKeyA key associated with the video.
librarySectionIDThe ID of the library section.
parentKeyThe unique identifier for the season.
grandparentKeyThe unique identifier for the TV show.
titleThe title of the video.
grandparentTitleThe title of the TV show.
typeThe type of media.
thumbThe thumbnail for the video.
parentThumbThe thumbnail for the season.
grandparentThumbThe thumbnail for the TV show.
grandparentArtThe background artwork used to represent the TV show.
indexThe index of the video.
parentIndexThe index of the season.
originallyAvailableAtThe original release date of the video.
viewedAtThe date and time in epoch time, the video was played.
accountIDThe unique ID associated with the account.

A Track element can also be found within the MediaContainer element. Each Track element represents on music track that was played from the Plex server.

Track Attributes
AttributeDescription
historyKeyThe unique identifier the history record.
keyThe relative URL of the music track information.
ratingKeyA key associated with the music track.
librarySectionIDThe ID of the library section.
parentKeyThe unique identifier for the artist.
grandparentKeyThe unique identifier for the album.
titleThe title of the music track.
parentTitleThe title of the artist.
grandparentTitleThe title of the album.
typeThe type of media.
thumbThe thumbnail for the music track.
parentThumbThe thumbnail for the artist.
grandparentThumbThe thumbnail for the album.
grandparentArtThe background artwork used to represent the album.
indexThe index of the music track.
parentIndexThe index of the artist.
viewedAtThe date and time in epoch time, the music track was played.
accountIDThe unique ID associated with the account.
deviceIDThe unique ID associated with the device.

Examples

curl -X GET http://{ip_address}:32400/status/sessions/history/all?X-Plex-Token={plex_token}
import requests
plex_url = http://{ip_address}:32400/status/sessions/history/all?X-Plex-Token={plex_token}
response = requests.get(plex_url)
print(response.text)
$response = Invoke-RestMethod 'http://{ip_address}:32400/status/sessions/history/all?X-Plex-Token={plex_token}' -Method 'GET'
Write-Output $response
Subscribe
Display