Listen for Events
Plex provides a way of pushing event notifications to a client over HTTP. This API command will open a connection to the Plex server to allow Plex to send notifications to the client when an event happens on the server.
URL
GET http://{ip_address}:32400/:/eventsource/notifications?filters={filters}&X-Plex-Token={plex_token}
Parameters
Name | Description |
---|---|
ip_address | The IP address of the Plex Media server. |
plex_token | The Plex token. |
filters | The filters parameter is optional. If not provided, then there will be no filter and all event notifications will be sent. The available filter options are outlined in the Filters section. |
Return Status
HTTP Code | Description |
---|---|
200 | Success - The request was successful. |
401 | Unauthorized - The Plex token provided was not valid. |
Response
When this API command is running a connection to the server is opened and remains open until the connection is closed. The content type for this command is text/event-stream
, which is a server-sent event stream.
While the connection is open, the server will send event details to the client as the events happen on the server.
The server will also send a ping
event every 10 seconds to ensure the client is still connected to the server.
For each event notification sent from the server, the following two fields are included:
Name | Description |
---|---|
event | The name of the event. |
data | Information associated with the event in JSON format. |
The event
field will always have the name of the event, however, the data
field can contain no data.
ping Event
The ping
event will happen every 10 seconds to ensure the client is still connected to the server. The data
field contains no information for a ping
event.
An example of the ping
event:
event: ping data: {}
activity Event
The activity
event occurs when there is some job being run on the server. A single activity can return multiple activity
notifications from the server.
An example of data returned for an activity
event is shown below:
event: activity data: {"ActivityNotification":{"event":"updated","uuid":"40874a0a-9558-4554-b070-0dae4e2f5b9c","Activity":{"uuid":"40874a0a-9558-4554-b070-0dae4e2f5b9c","type":"library.refresh.items","cancellable":false,"userID":1,"title":"Refreshing","subtitle":"Checking files","progress":0,"Context":{"key":"/library/collections/204922/children"}}}}
For an activity
event, the top-level object is the ActivityNotification
. This object contains fields about the activity.
Name | Description |
---|---|
event | The event of the activity, such as started , updated , or ended |
uuid | A unique identifier for the activity. |
Activity | More information about the activity. See the next table. |
Name | Description |
---|---|
uuid | A unique identifier for the activity. |
type | The type of activity being performed. |
cancellable | Indicates whether the activity can be cancelled. |
userID | The ID associated with the user running the activity. This ID matches one from the list of accounts on the server. |
title | The title of the activity. |
subtitle | The subtitle of the activity. |
progress | The progress, as a percentage, of the activity. |
Context | Additional context for the activity. See the next table. |
Name | Description |
---|---|
accessible | The item associated with the activity is accessible. |
analyzed | The item has been analyzed. |
exists | Indicates the item exists. |
key | The key for the item associated with the activity |
refreshed | Indicates the item has been refreshed. |
As mentioned earlier, a single activity can generate multiple notifications. Each notification would show the current progress for the activity, and then a final end notification once the activity has been completed.
playing Event
The playing
event will happen whenever media is played, paused, or stopped. The information in the data
field will contain information about the media and the play state at the time of the event.
The playing
event will return something like the following:
event: playing data: {"PlaySessionStateNotification":{"sessionKey":"45","clientIdentifier":"4b453df1-8fb1-4aee-bfb9-3ea219fce481","guid":"","ratingKey":"217468","url":"","key":"/library/metadata/217448","viewOffset":26530,"state":"paused"}}
The top-level object in the response is the PlaySessionStateNotification
object. This object contains details on the play state change from the server.
The following table lists the information included in the data
field for the PlaySessionStateNotification
object:
Name | Description |
---|---|
sessionKey | Unique key for the play session. |
clientIdentifier | The unique identifier associated with the client. Should match a device returned by the Get Devices API command. |
guid | A unique identifier for the play session. |
ratingKey | The unique key for the media item. |
url | The URL. It appears to return a blank value for media. |
key | The key to the information about the media item. |
viewOffset | The current play progress of the media in milliseconds. |
playQueueID | The ID associated to the current play queue. |
state | The play state of the media item. Valid values: playing , paused , stopped . |
transcodeSession | If the play session is being transcoded, this field will contain the unique identifier for the transcode session. |
transcodeSession.update Events
When media is transcoded several transcodeSession
notifications are sent. Plex will send update notifications for a transcode session using the transcodeSession.update
event.
An example of data associated with this event is shown below:
event: transcodeSession.update data: {"TranscodeSession":{"key":"/transcode/sessions/3gk8278lyxrc905hn8jgrgfr","throttled":false,"complete":false,"progress":1.2999999523162842,"size":-22,"speed":23.600000381469728,"error":false,"duration":8574912,"remaining":361,"context":"streaming","sourceVideoCodec":"h264","sourceAudioCodec":"dca","videoDecision":"copy","audioDecision":"transcode","protocol":"dash","container":"mp4","videoCodec":"h264","audioCodec":"aac","audioChannels":2,"width":1920,"height":1080,"transcodeHwRequested":true,"transcodeHwFullPipeline":false,"timeStamp":1704824487.95772,"maxOffsetAvailable":124.957,"minOffsetAvailable":0.0}}
The top-level object is the TranscodeSession
, and each property of the child object will contain information about that transcode session.
The following table outlines those properties.
Name | Description |
---|---|
key | The unique key for the transcode session. |
throttled | Indicates whether the transcode session is throttled. |
complete | Indicates the transcode session is complete. |
progress | The progress of the transcode session. |
size | The size. |
speed | The speed of the transcoding. 1.0 - the server is transcoding in real-time. Greater than 1.0 - the server is able to transcode fast enough. Less than 1.0 - the server is unable to transcode fast enough. |
error | Whether there is an error. |
duration | The length of time for the media item. |
remaining | The remaining media to be transcoded. |
context | The context of the transcode session. |
sourceVideoCodec | The source video codec. |
sourceAudioCodec | The source audio codec. |
videoDecision | How the video is being handled. |
audioDecision | How the audio is being handled. |
protocol | The streaming protocol. |
container | The streamining media container. |
videoCodec | The streaming video codec. |
audioCodec | The streaming audio codec. |
audioChannels | The streaming audio channels. |
width | The width of the media. |
height | The height of the media. |
transcodeHwRequested | Indicates the hardware was requested for transcoding. |
transcodeHwFullPipeline | Indicates the hardware was being used. |
transcodeHwRequested | Indicates the hardware was requested for transcoding. |
timeStamp | The current time stamp. |
maxOffsetAvailable | The current media max offset. |
minOffsetAvailable | The current media min offset. |
transcodeSession.end Events
event: transcodeSession.end data: {"TranscodeSession":{"key":"/transcode/sessions/3gk8278lyxrc905hn8jgrgfr","throttled":false,"complete":false,"progress":1.600000023841858,"size":-22,"speed":33.5,"error":false,"duration":8574912,"remaining":291,"context":"streaming","sourceVideoCodec":"h264","sourceAudioCodec":"dca","videoDecision":"copy","audioDecision":"transcode","protocol":"dash","container":"mp4","videoCodec":"h264","audioCodec":"aac","audioChannels":2,"width":1920,"height":1080,"transcodeHwRequested":true,"transcodeHwFullPipeline":false,"timeStamp":1704824487.95772}}
The top-level object is the TranscodeSession
, and each property of the child object will contain information about that transcode session.
The following table outlines those properties.
Name | Description |
---|---|
key | The unique key for the transcode session. |
throttled | Indicates whether the transcode session is throttled. |
complete | Indicates the transcode session is complete. |
progress | The progress of the transcode session. |
size | The size. |
speed | The speed of the transcoding. 1.0 - the server is transcoding in real-time. Greater than 1.0 - the server is able to transcode fast enough. Less than 1.0 - the server is unable to transcode fast enough. |
error | Whether there is an error. |
duration | The length of time for the media item. |
remaining | The remaining media to be transcoded. |
context | The context of the transcode session. |
sourceVideoCodec | The source video codec. |
sourceAudioCodec | The source audio codec. |
videoDecision | How the video is being handled. |
audioDecision | How the audio is being handled. |
protocol | The streaming protocol. |
container | The streamining media container. |
videoCodec | The streaming video codec. |
audioCodec | The streaming audio codec. |
audioChannels | The streaming audio channels. |
width | The width of the media. |
height | The height of the media. |
transcodeHwRequested | Indicates the hardware was requested for transcoding. |
transcodeHwFullPipeline | Indicates the hardware was being used. |
transcodeHwRequested | Indicates the hardware was requested for transcoding. |
timeStamp | The current time stamp. |
Remarks
Filters
To return specific events, you can apply filters to the API command. If a filter parameter is not passed into the command, then all events will be pushed to the client.
The following table lists valid filters that can be passed into the command.
Name | Description |
---|---|
activity | An activity is happening on the server. |
playing | When media is playing, paused, or stopped. |
transcodeSession.start | A transcoding session is started. |
transcodeSession.update | A transcoding session has been updated. |
transcodeSession.end | A transcoding session has ended. |
When passing in multiple filters, separate each filter value with a comma.
/:/eventsource/notifications?filters=activity,playing,transcodeSession.start,transcodeSession.update,transcodeSession.end
Examples
curl -X GET http://{ip_address}:32400/:/eventsource/notifications?filters={filters}&X-Plex-Token={plex_token}
import requests plex_url = http://{ip_address}:32400/:/eventsource/notifications?filters={filters}&X-Plex-Token={plex_token} response = requests.get(plex_url) print(response.text)
$response = Invoke-RestMethod 'http://{ip_address}:32400/:/eventsource/notifications?filters={filters}&X-Plex-Token={plex_token}' -Method 'GET' Write-Output $response
Script examples
Below are a list of post and articles that provide an example that use this API endpoint: