JSON-RPC API: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>Montellese
(Update of the development progress)
No edit summary
 
(134 intermediate revisions by 24 users not shown)
Line 1: Line 1:
== Overview ==
{{JSON-RPC_API_nav}}
JSON RPC is a HTTP-based or raw TCP Socket interface for communicating with XBMC. It replaces the soon-to-be-depreceated HTTP API, and offers a more secure and robust mechanism in the same format. It is based upon the [http://groups.google.com/group/json-rpc/web/json-rpc-2-0?pli=1 JSON RPC 2.0 specification].
{{mininav|[[Development]]}}


Each method in the interface can have different security needs which means one client may be allowed to only control playback while another can only read and manipulate the library. In version 2 (first stable) all clients are granted full authority but will later be forced to ask for privileges and the user of XBMC will have to grant said client access. The design of JSON RPC is that most methods should behave roughly the same and maintain consistency while hiding the mechanics of XBMC from the client creator.


In XBMC JSON RPC can be accessed over a variety of transports and has been designed from the ground up to be flexible to allow control over new transports simply. Some of the transports have different limitations which will be enforced upon the interaction over that transport. As an example HTTP Transports allow response and downloading of files while the Raw TCP Transport allows response and announcements (events and information XBMC sends to its clients). Depending on the clients needs it will choose one (or many) of the transports.


== Enabling JSON RPC ==
JSON-RPC is a HTTP- and/or raw TCP socket-based interface for communicating with Kodi. It replaces the deprecated HTTP API, and offers a more secure and robust mechanism in the same format. It is based upon the [http://jsonrpc.org/spec.html JSON-RPC 2.0 specification].
Since the interface is available on many transports enabling it will depends on the transport.
* Python. Always enabled
* HTTP. Enable webserver
* TCP. "Allow External Control of XBMC" for localhost control and "Allow Control from other computers" for access from outside localhost.


Note: The EventServer is a different interface for sending remote keypresses to XBMC, and must be enabled separately, some programs may use both interfaces.
Each method in the interface can have different security needs which means one client may be allowed to only control playback while another can only read and manipulate the library. In version 2 (first stable) and 4 all clients are granted full authority but will later be forced to ask for privileges and the user of Kodi will have to grant said client access. The design of JSON-RPC is that most methods should behave roughly the same and maintain consistency while hiding the mechanics of Kodi from the client creator.


== XBMC API ==
In Kodi JSON-RPC can be accessed over a variety of transports and has been designed from the ground up to be flexible to allow control over new transports easily. Some of the transports have different limitations which will be enforced upon the interaction over that transport. As an example HTTP transports allow response and downloading of files while the raw TCP transport allows response and notifications (events and information Kodi sends to its clients). Depending on the client's needs it will choose one (or many) of the available transports.<br />
The XBMC JSON api is split up into namespaces, which contain methods that can be called. These namespaces are:
<pre>
JSONRPC          A variety of standard JSONRPC calls
Player          Manages all available players
AudioPlayer      Audio playback control
VideoPlayer      Video playback control
Slideshow        Picture playback control
Playlist        Playlist Modification
Files            Shares information
AudioLibrary    Audio Library Information
VideoLibrary    Video Library Information
System          System Controls and Information
XBMC            Application controls
</pre>


=== JSONRPC ===
==== JSONRPC.Introspect ====
Returns a list of all available method calls
<pre>
PARAMETERS
getpermissions    boolean    OPTIONAL: return list of required permissions
getdescriptions    boolean    OPTIONAL: return list of method descriptions
filterbytransport  boolean    OPTIONAL: Return only methods available on this transport
</pre>


==== JSONRPC.Version ====
== Enabling JSON-RPC ==
Returns the version of this API (not JSONRPC version). An even number refers to a stable version while odd number is development.
Since the interface is available on many transports enabling it depends on the transport.
* Python: Always enabled
* HTTP: In System/Settings/Network/Services activate ''Allow control of Kodi via HTTP'' (see [[Webserver#Enabling_the_webserver|Enabling the webserver]])
* TCP: In System/Settings/Network/Services activate ''Allow programs on this system to control Kodi'' for localhost access only and ''Allow programs on other systems to control Kodi'' for access from other computers as well


==== JSONRPC.Permission ====
Note: The [[EventServer]] is a different interface for sending remote keypresses to Kodi, and must be enabled separately, some programs may use both interfaces.
Returns a list of client permissions


==== JSONRPC.Ping ====
== Transports & Functionalities ==
Returns pong!
=== Transports ===
==== Python ====
The ''Python'' transport can only be used by Kodi addons through the '''executeJSONRPC''' method provided by the '''xbmc''' python library. As it must be available to every addon in an Kodi installation it must not be enabled or disabled by the user.


==== JSONRPC.GetAnnouncementFlags ====
==== HTTP ====
Returns what announcements the client is listening for
The ''HTTP'' transport can be used by third-party applications running on the same machine as Kodi or on a different machine which can access the machine running Kodi using the [http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP] protocol. Because this transport allows applications outside Kodi to control Kodi, it has to be manually enabled (see [[#Enabling JSON-RPC|Enabling JSON-RPC]]) by the user.


==== JSONRPC.SetAnnouncementFlags ====
===== POST =====
Sets what announcements the client is listening for
Third-party applications can access Kodi's JSON-RPC API by sending JSON-RPC requests embedded in HTTP [http://en.wikipedia.org/wiki/POST_(HTTP) POST] requests to the following URL
<pre>http://<your-ip>:<your-port>/jsonrpc</pre>


==== JSONRPC.Announce ====
Starting with Frodo nightly builds it is mandatory to set the HTTP header field '''Content-Type: application/json'''
Send a message to other clients. An announcement made by a client will fall under the "Other" announcement category so a client can't pretend to send XBMC messages (which will never send on "Other").
<pre>


PARAMETERS
===== GET =====
sender            string    the sender of the announcement (your client name)
Third-party application can access Kodi's JSON-RPC API by sending JSON-RPC requests embedded in a HTTP GET parameter called ''request''. The JSON-RPC request must be URL encoded and sent to the following URL
message            string    description of the announcement
<pre>http://<your-ip>:<your-port>/jsonrpc?request=<url-encoded-request></pre>
data              string    OPTIONAL: data associated with this message
</pre>


=== Player ===
==== TCP ====
==== Player.GetActivePlayers ====
The ''TCP'' transport can be used by third-party applications running on the same machine as Kodi or on a different machine which can access the machine running Kodi using the [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] protocol. Because this transport allows applications outside Kodi to control Kodi it has to be manually enabled (see [[#Enabling JSON-RPC|Enabling JSON-RPC]]) by the user. Once enabled, third-party applications can access Kodi's JSON-RPC API by opening a TCP [http://en.wikipedia.org/wiki/Internet_socket socket] on port 9090 (this port can be configured in the [[Advancedsettings.xml#<jsonrpc>|advanced settings]] file) and sending raw JSON-RPC requests over that socket. Please note that no delimiters are provided in between notifications and/or responses. As such, your client needs to be able to deal with this, eg. by counting and matching curly braces ({}).
Returns which players are active (available for querying)<br />
Note: AudioPlayer, VideoPlayer and Slideshow methods are only available if there respective player is active, use this function to obtain that information
<pre>
RESULT
video              boolean    True if video is available, false otherwise
audio              boolean    True if audio is available, false otherwise
picture            boolean    True if pictures are playing, false otherwise
</pre>
 
=== AudioPlayer ===
==== AudioPlayer.State ====
Gets the state of the audio player
<pre>
RESULT
playing            boolean    True if audio is currently playing
paused            boolean    True if audio is currently paused
partymode          boolean    True if party mode is enabled
</pre>
 
==== AudioPlayer.PlayPause ====
Pauses or unpauses playback, returns new state
<pre>
RESULT
playing            boolean    True if audio is currently playing
paused            boolean    True if audio is currently paused
</pre>
 
==== AudioPlayer.Stop ====
Stops playback
 
==== AudioPlayer.SkipPrevious ====
Skips to the previous item in the playlist
 
==== AudioPlayer.SkipNext ====
Skips to the next item in the playlist
 
==== AudioPlayer.BigSkipBackward ====
Skips backward in the current track by a big amount
 
==== AudioPlayer.BigSkipForward ====
Skips forward in the current track by a big amount
 
==== AudioPlayer.SmallSkipBackward ====
Skips backward in the current track by a small amount
 
==== AudioPlayer.SmallSkipForward ====
Skips forward in the current track by a small amount
 
==== AudioPlayer.Rewind ====
Rewind current track
 
==== AudioPlayer.Forward ====
Play current track forwards (Fast Forwards? unknown)
 
==== AudioPlayer.GetTime ====
Gets the state of the audio player, including time information, to the second
<pre>
RESULT
time              number    Position in current track in seconds
total              number    Duration of current track in seconds
playing            boolean    True if audio is currently playing
paused            boolean    True if audio is currently paused
</pre>
 
==== AudioPlayer.GetTimeMS ====
Gets the state of the audio player, including time information, to the millisecond
<pre>
RESULT
time              number    Position in current track in milliseconds
total              number    Duration of current track in milliseconds
playing            boolean    True if audio is currently playing
paused            boolean    True if audio is currently paused
</pre>
 
==== AudioPlayer.GetPercentage ====
Gets a percentage, of what is not obviously documented, presumably Position/Duration*100
<pre>
RESULT            number    Percentage
</pre>
 
==== AudioPlayer.SeekTime ====
Seek to a position in the track defined by position in seconds
<pre>
PARAMETER          number    Position to seek to
</pre>
 
==== AudioPlayer.SeekPercentage ====
Seek to a position in the track defined by a percentage (of total duration?)
<pre>
PARAMETER          number    Percentage to seek to
</pre>
 
=== VideoPlayer ===
VideoPlayer contains exactly the same methods as AudioPlayer, see method in that namespace.
 
=== PicturePlayer ===
==== PicturePlayer.PlayPause ====
Pauses or unpauses slideshow.
 
==== PicturePlayer.Stop ====
Stops playback.
 
==== PicturePlayer.SkipPrevious ====
Skips to the previous item in the slideshow.
 
==== PicturePlayer.SkipNext ====
Skips to the next item in the slideshow.
 
==== PicturePlayer.MoveLeft ====
In a zoomed view, pans the viewport to the left.
 
==== PicturePlayer.MoveRight ====
In a zoomed view, pans the viewport to the right.
 
==== PicturePlayer.MoveDown ====
In a zoomed view, pans the viewport downwards.
 
==== PicturePlayer.MoveUp ====
In a zoomed view, pans the viewport upwards.
 
==== PicturePlayer.ZoomOut ====
Zooms the viewport out.
 
==== PicturePlayer.ZoomIn ====
Zooms the viewport in.
 
==== PicturePlayer.Zoom ====
Zoom to a defined level
<pre>
PARAMETER          number    Zoom level to seek to, as a whole number between 1-10
</pre>
 
==== PicturePlayer.Rotate ====
Rotate the current picture (clockwise or anticlockwise?)
 
=== AudioPlaylist ===
==== AudioPlaylist.Play ====
Starts playing a playlist
<pre>
PARAMETER          number    id number of a song to play
OR
PARAMETER
songid            number    id number of a song to play
 
RESULT
status            boolean    whether method succeeded
</pre>
 
==== AudioPlaylist.SkipPrevious ====
Skips to the previous track in the playlist
 
==== AudioPlaylist.SkipNext ====
Skips to the next track in the playlist
 
==== AudioPlaylist.GetItems ====
Returns a list of items in the playlist, if you chose the right playlist type, also returns state information
<pre>
RESULT
items              array      a list of items in the playlist (This result is optional)
an item: {"fanart":"", "file":"", "label":"", "thumbnail":""}
current            number?    (id? of) current song    (This result is optional)
playing            boolean    whether currently playing  (This result is optional)
paused            boolean    whether currently paused  (This result is optional)
 
start              number
total              number
end                number
</pre>
 
==== AudioPlaylist.Add ====
Adds a track to the current audio playlist
<pre>
PARAMETER       
file              string            uri of the file to add
</pre>
 
==== AudioPlaylist.Clear ====
Clears the current audio playlist
 
==== AudioPlaylist.Shuffle ====
Shuffles the current audio playlist
 
==== AudioPlaylist.UnShuffle ====
Removes the shuffle from the current audio playlist
 
=== VideoPlaylist ===
Contains exact the same methods as AudioPlaylist, except it affects the current video playlist, see AudioPlaylist method calls
 
=== Playlist ===
==== Playlist.Create ====
Creates a virtual playlist, optionally from another file or virtual playlist
 
<pre>
PARAMETER
playlist-virtual  string    OPTIONAL: id of an existing virtual playlist to copy from
playlist-file      string    OPTIONAL: id of an existing file playlist to copy from
 
RESULT
playlist-virtual  string    id of the new playlist
</pre>
 
==== Playlist.Destroy ====
Destroys (deletes) a virtual playlist
<pre>
PARAMETER      string    id of virtual playlist to delete
</pre>
 
==== Playlist.GetItems ====
Returns a list of items in the playlist, if you chose the right playlist type, also returns state information
<pre>
PARAMETER
playlist-file      string    OPTIONAL: id of file playlist
playlist-virtual  string    OPTIONAL: id of virtual playlist
 
RESULT
items              array      a list of items in the playlist
name              string    name of the playlist
 
 
playing            boolean    whether currently playing  (This result is optional)
paused            boolean    whether currently paused  (This result is optional)
 
start              number
total              number
end                number
 
 
</pre>
 
==== Playlist.Add ====
Adds file(s) to a given playlist (file or virtual)
<pre>
PARAMETER
playlist-file      string    OPTIONAL: id of file playlist
playlist-virtual  string    OPTIONAL: id of virtual playlist
file              string    the file to add (path)
</pre>
 
==== Playlist.Remove ====
Removes file from a given playlist (file or virtual)
<pre>
PARAMETER
playlist-file      string        OPTIONAL: id of file playlist
playlist-virtual  string        OPTIONAL: id of virtual playlist
item              string/number id of item to remove
</pre>
 
==== Playlist.Swap ====
Swaps the position of two items in a given playlist
<pre>
PARAMETER
playlist-file      string    OPTIONAL: id of file playlist
playlist-virtual  string    OPTIONAL: id of virtual playlist
item1              number    id of first item
item2              number    id of second item
</pre>
 
==== Playlist.Shuffle ====
Shuffles the playlist
<pre>
PARAMETER
playlist-file      string    OPTIONAL: id of file playlist
playlist-virtual  string    OPTIONAL: id of virtual playlist
</pre>
 
==== Playlist.UnShuffle ====
Removes the shuffle from the playlist
<pre>
PARAMETER
playlist-file      string    OPTIONAL: id of file playlist
playlist-virtual  string    OPTIONAL: id of virtual playlist
</pre>
 
=== Files ===
Many functions in this namespace allow filtering by type, valid types are the following:
<pre>
video
music
pictures
files
programs
</pre>
==== Files.GetSources ====
Returns a list of available source directories (directories in root folder)
<pre>
PARAMETER
media              string    media type filter, see Files namespace documentation for details, media entry not included if no data
 
RESULT
shares            array      a list of file items in the directory {"fanart":"", "file":"","label":""}
 
 
start              number
total              number
end                number
 
</pre>
 
==== Files.Download ====
Returns information about how to download a file (does not return the file itself)
<pre>
PARAMETER        string    URI to a file (not a folder)
 
 
RESULT
path              string
</pre>
 
==== Files.GetDirectory ====
Returns a list of items in a directory, items can be filtered by type.
<pre>
PARAMETER
directory          string    the directory to list, e.g. foo/bar
media              string    media type filter, see Files namespace documentation for details
 
RESULT
directories        array      sub-directories in this directory
files              array      files in this directory
 
 
start              number
total              number
end                number
 
 
</pre>
 
=== AudioLibrary ===
==== AudioLibrary.GetArtists ====
Returns a list of artists in the audio library
<pre>
PARAMETER
genreid            number    filters by this genre id, -1 means all.
 
RESULT
artists            array      artists in the library { "artistid" : number ,"fanart":string,"label":string, "thumbnail" :stringORnotpresent}
 
start              number
total              number
end                number
 
</pre>
 
==== AudioLibrary.GetAlbums ====
Returns a list of albums in the audio library
<pre>
PARAMETER
genreid            number    filters by this genre id
artistid          number    filters by this artist id
start              number    integer value to start result listing from
end                number    integer value to end result listing from
 
RESULT
albums            array      artists in the library {"albumid" : number, "fanart" : string, "label" : string, "thumbnail" : string}
 
start              number
total              number
end                number
 
</pre>
 
==== AudioLibrary.GetSongs ====
Returns a list of albums in the audio library
<pre>
PARAMETER
fields            string    OPTIONAL: fields to return information for
genreid            number    filters by this genre id
artistid          number    filters by this artist id
albumid            number    filters by this album id
 
RESULT
albums            array      artists in the library {"fanart" : string, "file" : string, "label" : string, "songid" : number, "thumbnail" : string}
 
start              number
total              number
end                number
 
</pre>
 
==== AudioLibrary.ScanForContent ====
Scans file system for new audio content using ExecBuiltIn("updatelibrary(music)") command
 
=== VideoLibary ===
==== VideoLibrary.GetMovies ====
Returns a list of movies in the video library
 
for a list of available fields look to : libjsonrpc/FileItemHandler.cpp
 
<pre>
PARAMETER
fields            string    OPTIONAL: fields to return information for
sortmethod        string    OPTIONAL: method to sort the returned list
sortorder        string    OPTIONAL: order of sorting, "ascending" or "descending"
start            number    OPTIONAL: index to start listing from
end              number    OPTIONAL: index to end listing at


RESULT
==== WebSocket ====
movies            array      movies in the library { "fanart" : string, "file" : string, "label" : string, "movieid" : number, "thumbnail" : string}
The ''WebSocket'' transport has been added since Version 5 and can be used by third-party applications running on the same machine as Kodi or on a different machine which can access the machine running Kodi using the [http://en.wikipedia.org/wiki/WebSocket Websocket] protocol. The supported versions are 8 (draft [http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10 hybi-10]) and 13 ([http://tools.ietf.org/html/rfc6455 RFC 6455]). Because this transport allows applications outside Kodi to control Kodi it has to be manually enabled (see [[#Enabling JSON-RPC|Enabling JSON-RPC]]) by the user. Once enabled, third-party applications can access Kodi's JSON-RPC API by sending a WebSocket protocol handshake to the following URI
</pre>
<pre>ws://<your-ip>:<configured tcp port>/jsonrpc</pre>
It is important to send the handshake on the port of Kodi's TCP server (by default 9090, but this port can be configured in the [[Advancedsettings.xml#<jsonrpc>|advanced settings]] file). After having successfully finished the handshake third-party applications can send WebSocket protocl messages over that connection.


==== VideoLibrary.GetTVShows ====
=== Functionalities ===
Returns a list of tv shows in the video library
==== Response ====
<pre>
The ''Response'' functionality is the only functionality that should be present in every transport available as it describes the functionality to respond to a JSON-RPC request with a valid JSON-RPC response (be it an error message or an actual response).
PARAMETER
fields            string    OPTIONAL: fields to return information for
sortmethod        string    OPTIONAL: method to sort the returned list
sortorder        string    OPTIONAL: order of sorting, "ascending" or "descending"
start            number    OPTIONAL: index to start listing from
end              number    OPTIONAL: index to end listing at


RESULT
==== Notifications ====
tvshows          array      movies in the library
The ''Notifications'' functionality includes both server-side (from the server to clients) and client-side (from clients to the server) notifications. A JSON-RPC notification is a valid JSON-RPC request with no ''id'' property. Following the JSON-RPC 2.0 specification any JSON-RPC request with no ''id'' must be considered as a notification and the receiver must not send a response upon a notification.
</pre>


==== VideoLibrary.GetSeasons ====
In the specific case of Kodi, server-side notifications are used to inform clients about certain events to relieve clients of the need to periodically poll for certain events. Furthermore there are two ways of client-side notifications. Using JSONRPC.NotifyAll it is possible to ask Kodi to relay the message in the JSON-RPC request to all other connected clients. The second way is to send JSON-RPC requests without an ''id'' property in case the client does not care about the response (e.g. the method Player.Stop does not return any useful information to the client).
Returns a list of seasons for a given tv show
<pre>
PARAMETER
tvshowid          number    id of the tv show to get seasons for


RESULT
==== Direct file download ====
seasons          array      seasons for the tv show
The ''Direct file download'' functionality is the ability to directly download files from Kodi by calling Files.Download. In this case the term ''direct'' means that the download happens within the JSON-RPC response of the Files.Download request.
</pre>


==== VideoLibrary.GetEpisodes ====
==== Redirected file download ====
Returns a list of episodes for a tv show and season
The ''Redirected file download'' functionality is the ability to indirectly download files from Kodi by calling Files.PrepareDownload and using the data received in the response to download the file over a different protocol (like HTTP, FTP ...) or another socket. As the ''Redirected file download'' is very transport specific, it must be handled separately for every transport supporting it.
<pre>
PARAMETER
tvshowid          number    id of the tv show
season            number    id of the season to get episodes for


RESULT
=== Comparison ===
episodes          array      seasons for the tv show
The following table shows all the available transports and what functionalities they support
</pre>
{| class="prettytable" style="margin-right: 0;"
!style="padding-left: 5px; padding-right: 10px;" colspan="2"|Transport
!style="padding-left: 10px; padding-right: 10px;"|Response
!style="padding-left: 10px; padding-right: 10px;"|Notifications
!style="padding-left: 10px; padding-right: 10px;"|Direct file<br />download
!style="padding-left: 10px; padding-right: 10px;"|Redirected file<br />download
|-
|style="padding-left: 5px;" colspan="2"|Python
|{{yes}}
|{{no}}
|{{no}}
|{{no}}
|-
|style="padding-left: 5px;" colspan="2"|[http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP]
|{{yes}}
|{{yes}}
|{{no}}
|{{no}}
|-
|style="padding-left: 5px; padding-right:5px;" rowspan="2"|[http://en.wikipedia.org/wiki/HTTP HTTP]
|style="padding-left: 5px; padding-right:5px;"|POST
|{{yes}}
|{{no}}
|{{no}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right:5px;"|GET<sup>1</sup>
|{{yes}}
|{{no}}
|{{no}}
|{{yes}}
|-
|style="padding-left: 5px;" colspan="2"|[http://en.wikipedia.org/wiki/WebSocket WebSocket]<sup>1</sup>
|{{yes}}
|{{yes}}
|{{no}}
|{{no}}
|-
|}
<sup>1</sup> Added in Version 5


==== VideoLibrary.GetMusicVideos ====
== API versions ==
Returns a list of Music videos in the video library
The JSON-RPC API exposed by Kodi is constantly extended to provide better and more functionality to third party applications. For that reason Kodi provides a version information through the '''JSONRPC.Version''' method. The rule is that odd version numbers describe an API state, that is not stable and under heavy development whereas even version numbers describe a stable API. Therefore the version number can be used by third-party clients to check if their application might not be fully compatible with the JSON-RPC API exposed by a user's Kodi installation.
<pre>
PARAMETER
artistid          number    id of the artist
albumid          number     id of the album
fields            string    OPTIONAL: fields to return information for
sortmethod        string    OPTIONAL: method to sort the returned list
sortorder        string    OPTIONAL: order of sorting, "ascending" or "descending"
start            number    OPTIONAL: index to start listing from
end              number    OPTIONAL: index to end listing at


RESULT
Starting with XBMC v12 (Frodo) we started using a new versioning system (<major>.<minor>.<patch>) for the JSON-RPC API. Frodo stable is version 6.0.0 and from now on with every bugfix the <patch> part of the version is increased, with every feature addition to the API, the <minor> version is increased (and the <patch> version reset to 0) and with every backwards incompatible change, the <major> version is increased.
musicvideos      array      music videos in the library
</pre>


==== VideoLibrary.GetRecentlyAddedMovies ====
{| class="prettytable" style="margin-right: 0;"
eturns a list of recently added movies in the video library
!colspan="3"|Release
<pre>
!colspan="6"|JSON-RPC 2.0 specification
PARAMETER
!colspan="5"|Transports
fields            string    OPTIONAL: fields to return information for
|-
sortmethod        string    OPTIONAL: method to sort the returned list
!style="padding-left: 5px; padding-right: 5px; width: 6em; text-align: left;"|API Version
sortorder        string    OPTIONAL: order of sorting, "ascending" or "descending"
!style="padding-left: 10px; padding-right: 10px; width: 5em;"|Version
start            number    OPTIONAL: index to start listing from
!style="padding-left: 10px; padding-right: 10px; width: 4em;"|Name
end              number    OPTIONAL: index to end listing at
!style="padding-left: 10px; padding-right: 10px;"|Method calls
!style="padding-left: 10px; padding-right: 10px;"|Notifications<br />(server-side)
!style="padding-left: 10px; padding-right: 10px;"|Notifications<br />(client-side)
!style="padding-left: 10px; padding-right: 10px;"|Parameters<br />by-name
!style="padding-left: 10px; padding-right: 10px;"|Parameters<br />by-position
!style="padding-left: 10px; padding-right: 10px;"|Batch requests


RESULT
!style="padding-left: 10px; padding-right: 10px;"|Python
movies            array      movies in the library
!style="padding-left: 10px; padding-right: 10px;"|TCP
</pre>
!style="padding-left: 10px; padding-right: 10px;"|HTTP POST
!style="padding-left: 10px; padding-right: 10px;"|HTTP GET
!style="padding-left: 10px; padding-right: 10px;"|WebSocket
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 2
|style="padding-left: 5px; padding-right: 5px;"|10.0
|style="padding-left: 5px; padding-right: 5px;"|Dharma
|{{yes}}
|{{yes}}
|{{no}}
|{{yes}}
|{{no}}
|{{no}}


==== VideoLibrary.GetRecentlyAddedEpisodes ====
|{{yes}}
Returns a list of recently added episodes to the library
|{{yes}}
<pre>
|{{yes}}
PARAMETER
|{{no}}
|{{no}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 3 / 4
|style="padding-left: 5px; padding-right: 5px;"|pre-11 / 11.0
|style="padding-left: 5px; padding-right: 5px;"|Eden
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


RESULT
|{{yes}}
episodes          array      seasons for the tv show
|{{yes}}
</pre>
|{{yes}}
|{{no}}
|{{no}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 5 / 6
|style="padding-left: 5px; padding-right: 5px;"|pre-12 / 12.0
|style="padding-left: 5px; padding-right: 5px;"|Frodo
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== VideoLibrary.GetRecentlyAddedMusicVideos ====
|{{yes}}
Returns a list of Music videos in the video library
|{{yes}}
<pre>
|{{yes}}
PARAMETER
|{{yes}}
fields            string    OPTIONAL: fields to return information for
|{{yes}}
sortmethod        string    OPTIONAL: method to sort the returned list
|-
sortorder        string    OPTIONAL: order of sorting, "ascending" or "descending"
|style="padding-left: 5px; padding-right: 5px;"|Version 6
start            number    OPTIONAL: index to start listing from
|style="padding-left: 5px; padding-right: 5px;"|13.0
end              number    OPTIONAL: index to end listing at
|style="padding-left: 5px; padding-right: 5px;"|Gotham
</pre>
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== VideoLibrary.ScanForContent ====
|{{yes}}
Scans file system for new video content
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|13.1
|style="padding-left: 5px; padding-right: 5px;"|Gotham
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


=== System ===
|{{yes}}
==== System.Shutdown ====
|{{yes}}
Shuts down the system
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|13.2
|style="padding-left: 5px; padding-right: 5px;"|Gotham
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== System.Suspend ====
|{{yes}}
Suspends the system
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|14.0
|style="padding-left: 5px; padding-right: 5px;"|Helix
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== System.Hibernate ====
|{{yes}}
Hibernates the system
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|14.1
|style="padding-left: 5px; padding-right: 5px;"|Helix
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== System.Reboot ====
|{{yes}}
Reboots the system
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|14.2
|style="padding-left: 5px; padding-right: 5px;"|Helix
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== System.GetInfoLabels ====
|{{yes}}
Get info labels about the system
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|15.0
|style="padding-left: 5px; padding-right: 5px;"|Isengard
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


<pre>
|{{yes}}
PARAMETER        array      of string    <field name>s to return information for
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|15.1
|style="padding-left: 5px; padding-right: 5px;"|Isengard
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


RESULT            array      of object
|{{yes}}
<field name>    string    label that field 
|{{yes}}
</pre>
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|15.2
|style="padding-left: 5px; padding-right: 5px;"|Isengard
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== System.GetInfoBooleans ====
|{{yes}}
Get info booleans about the system
|{{yes}}
Available field names: <code>system.canshutdown  system.canpowerdown  system.cansuspend  system.canhibernate  system.canreboot</code>
|{{yes}}
<pre>
|{{yes}}
PARAMETER        array      of string    <field name>s to return information for
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|16.0
|style="padding-left: 5px; padding-right: 5px;"|Jarvis
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


RESULT            array      of object
|{{yes}}
<field name>    boolean    value of that field 
|{{yes}}
</pre>
|{{yes}}
Example parameters:<br />
|{{yes}}
<code>[ 'system.canshutdown', 'system.cansuspend' ]</code>
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 6
|style="padding-left: 5px; padding-right: 5px;"|16.1
|style="padding-left: 5px; padding-right: 5px;"|Jarvis
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


Example result: <br />
|{{yes}}
<code>[ { 'system.canshutdown' : true }, { 'system.cansuspend' : true }]</code>
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 8
|style="padding-left: 5px; padding-right: 5px;"|17.0
|style="padding-left: 5px; padding-right: 5px;"|Krypton
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


=== XBMC ===
|{{yes}}
==== XBMC.GetVolume ====
|{{yes}}
Gets the current volume
|{{yes}}
<pre>
|{{yes}}
RESULT            number    volume 
|{{yes}}
</pre>
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 10
|style="padding-left: 5px; padding-right: 5px;"|18
|style="padding-left: 5px; padding-right: 5px;"|Leia
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== XBMC.SetVolume ====
|{{yes}}
Sets the current volume as an int percent
|{{yes}}
<pre>
|{{yes}}
PARAMETER        number    volume to set to
|{{yes}}<sup>1</sup>
</pre>
|{{yes}}
|-
|style="padding-left: 5px; padding-right: 5px;"|Version 12
|style="padding-left: 5px; padding-right: 5px;"|19
|style="padding-left: 5px; padding-right: 5px;"|Matrix
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}


==== XBMC.ToggleMute ====
|{{yes}}
Toggle volume mute on/off, returns same as XBMC.GetVolume
|{{yes}}
|{{yes}}
|{{yes}}<sup>1</sup>
|{{yes}}
|-
|}
<sup>1</sup>For information requests only, actions require POST


==== XBMC.Play ====
{| class="prettytable" style="margin-right: 0;"
Starts playback
!colspan="3"|Release
!|JSONRPC.Version
|-
!style="padding-left: 10px; padding-right: 10px;"|Date
!style="padding-left: 10px; padding-right: 10px;"|Version
!style="padding-left: 10px; padding-right: 10px;"|Codename
!style="padding-left: 10px; padding-right: 10px;"|["version"]
|-
|18 December 2010
|10.0
|Dharma
|2
|-
|10 March 2011
|10.1
|Dharma
|2
|-
| style="background:#eee;" |24 March 2012
| style="background:#eee;" |11.0
| style="background:#eee;" |Eden
| style="background:#eee;" |4
|-
|29 January 2013
|12.0
|Frodo
|{"major":6,"minor":0,"patch":0}
|-
|18 March 2013
|12.1
|Frodo
|{"major":6,"minor":0,"patch":3}
|-
|03 May 2013
|12.2
|Frodo
|{"major":6,"minor":0,"patch":3}
|-
|24 December 2013
|12.3
|Frodo
|{"major":6,"minor":0,"patch":3}
|-
| style="background:#eee;" | 04 May 2014
| style="background:#eee;" | 13.0
| style="background:#eee;" | Gotham
| style="background:#eee;" | {"major":6,"minor":14,"patch":3}
|-
| style="background:#eee;" | 05 June 2014
| style="background:#eee;" | 13.1
| style="background:#eee;" | Gotham
| style="background:#eee;" | {"major":6,"minor":14,"patch":3}
|-
| style="background:#eee;" | 17 August 2014
| style="background:#eee;" | 13.2
| style="background:#eee;" | Gotham
| style="background:#eee;" | {"major":6,"minor":14,"patch":3}
|-
|23 December 2014
|14.0
|Helix
|{"major":6,"minor":21,"patch":2}
|-
|30 January 2014
|14.1
|Helix
|{"major":6,"minor":21,"patch":2}
|-
|26 March 2014
|14.2
|Helix
|{"major":6,"minor":21,"patch":2}
|-
| style="background:#eee;" | 21 July 2015
| style="background:#eee;" | 15.0
| style="background:#eee;" | Isengard
| style="background:#eee;" | {"major":6,"minor":25,"patch":2}
|-
| style="background:#eee;" | 16 August 2015
| style="background:#eee;" | 15.1
| style="background:#eee;" | Isengard
| style="background:#eee;" | {"major":6,"minor":25,"patch":2}
|-
| style="background:#eee;" | 19 October 2015
| style="background:#eee;" | 15.2
| style="background:#eee;" | Isengard
| style="background:#eee;" | {"major":6,"minor":25,"patch":2}
|-
|21 February 2016
|16.0
|Jarvis
|{"major":6,"minor":32,"patch":4}
|-
|24 April 2016
|16.1
|Jarvis
|{"major":6,"minor":32,"patch":5}
|-
| style="background:#eee;" | 05 February 2017
| style="background:#eee;" | 17.0
| style="background:#eee;" | Krypton
| style="background:#eee;" | {"major":8,"minor":0,"patch":0}
|-
| style="background:#eee;" | 20 March 2017
| style="background:#eee;" | 17.1
| style="background:#eee;" | Krypton
| style="background:#eee;" | {"major":8,"minor":0,"patch":0}
|-
| style="background:#eee;" | 23 May 2017
| style="background:#eee;" | 17.2
| style="background:#eee;" | Krypton
| style="background:#eee;" | {"major":8,"minor":0,"patch":0}
|-
| style="background:#eee;" | 24 May 2017
| style="background:#eee;" | 17.3
| style="background:#eee;" | Krypton
| style="background:#eee;" | {"major":8,"minor":0,"patch":0}
|-
| style="background:#eee;" | 22 August 2017
| style="background:#eee;" | 17.4
| style="background:#eee;" | Krypton
| style="background:#eee;" | {"major":8,"minor":0,"patch":0}
|-
| style="background:#eee;" | 23 October 2017
| style="background:#eee;" | 17.5
| style="background:#eee;" | Krypton
| style="background:#eee;" | {"major":8,"minor":0,"patch":0}
|-
| style="background:#eee;" | 14 November 2017
| style="background:#eee;" | 17.6
| style="background:#eee;" | Krypton
| style="background:#eee;" | {"major":8,"minor":0,"patch":0}
|-
| 29 January 2019
| 18.0
| Leia
| {"major":10,"minor":1,"patch":1}
|-
| 17 February 2019
| 18.1
| Leia
| {"major":10,"minor":1,"patch":2}
|-
| 22 April 2019
| 18.2
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 27 June 2019
| 18.3
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 01 September 2019
| 18.4
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 17 November 2019
| 18.5
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 02 March 2020
| 18.6
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 21 May 2020
| 18.7
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 01 June 2020
| 18.7.1
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 14 June 2020
| 18.7.2
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 29 July 2020
| 18.8
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| 24 October 2020
| 18.9
| Leia
| {"major":10,"minor":3,"patch":0}
|-
| style="background:#eee;" | 20 February 2021
| style="background:#eee;" | 19.0
| style="background:#eee;" | Matrix
| style="background:#eee;" | {"major":12,"minor":2,"patch":1}
|-
| style="background:#eee;" | 10 May 2021
| style="background:#eee;" | 19.1
| style="background:#eee;" | Matrix
| style="background:#eee;" | {"major":12,"minor":3,"patch":0}
|-
| style="background:#eee;" | 09 October 2021
| style="background:#eee;" | 19.2
| style="background:#eee;" | Matrix
| style="background:#eee;" | {"major":12,"minor":4,"patch":0}
|-
| style="background:#eee;" | 28 October 2021
| style="background:#eee;" | 19.3
| style="background:#eee;" | Matrix
| style="background:#eee;" | {"major":12,"minor":4,"patch":0}
|-
| style="background:#eee;" | 04 March 2022
| style="background:#eee;" | 19.4
| style="background:#eee;" | Matrix
| style="background:#eee;" | {"major":12,"minor":4,"patch":0}
|-
| TBA 2022
| 20.0
| Nexus
| {"major":12,"minor":10,"patch":2}
|-
|}


==== XBMC.StartSlideshow ====
== Documentation ==
Starts slideshow
Kodi's JSON-RPC API has been designed to be self-documented i.e. a call to JSONRPC.Introspect results in a JSON-RPC response containing a documentation for all the available methods and data types. While this documentation is very incomplete and partly wrong for version 2 it is provided as a full [http://tools.ietf.org/html/draft-zyp-json-schema-03 JSON schema] starting with version 3. As the documentation retrieved in that way is always specific to the used version of Kodi, it is (especially for development versions) the best documentation available and should be preferred over the wiki documentation as the latter always documents the API of the latest development.
<pre>
PARAMETER        string    command to start slideshow with
OR
PARAMETER
directory        string    directory to show pictures from
random          boolean    True if show in random order
recursive        boolean    True if include pictures from subdirectories
</pre>
==== XBMC.Log ====
Logs a line in xbmc.log
<pre>
PARAMETER        string    text to log
OR
PARAMETER
message          string    text to log
level            string    log level, "debug", "info", "notice", "warning", "error", "severe", "fatal", "none"
</pre>
 
==== XBMC.Quit ====
Exits XBMC


== Debugging ==
== Debugging ==
=== Output format ===
=== Output format ===
To be able to support easier debugging of (third party) development using the JSON RPC API, the JSON output generated by XBMC can be pretty printed by setting
To be able to support easier debugging of (third-party) development using the JSON-RPC API, the JSON output generated by Kodi can be pretty-printed by setting
<source lang="xml">
<syntaxhighlight lang="xml" enclose="div">
<jsonrpc>
<jsonrpc>
     <compactoutput>false</compactoutput>
     <compactoutput>false</compactoutput>
</jsonrpc>
</jsonrpc>
</source>
</syntaxhighlight>
in the [[Advancedsettings.xml#.3Cjsonrpc.3E|advancedsettings.xml]]. Default JSON output will be in compact format to minimize sent data (especially useful for mobile devices).
in the [[Advancedsettings.xml#.3Cjsonrpc.3E|advancedsettings.xml]]. Default JSON output will be in compact format to minimize sent data (especially useful for mobile devices).


=== Direct interaction ===
=== Direct interaction ===
To be able to test some methods of XBMC's JSON RPC API it can be of great help to be able to send a single hand-written JSON RPC request to XBMC to see its effect and the generated response. Depending on the transport protocol used there are different possibilities to do that:
To be able to test some methods of Kodi's JSON-RPC API, it can be of great help to be able to send a single hand-written JSON-RPC request to Kodi to see its effect and the generated response. Depending on the transport protocol used there are different possibilities to do that:


==== TCP ====
==== TCP ====
With a '''[http://en.wikipedia.org/wiki/Telnet telnet]''' connection (using [http://en.wikipedia.org/wiki/PuTTY PuTTY] on Windows or telnet on Linux) to port 9090 of the machine running XBMC it is possible to send and receive raw json data to/from XBMC.
With a [http://en.wikipedia.org/wiki/Telnet telnet] connection (using [http://en.wikipedia.org/wiki/PuTTY PuTTY] on Windows or telnet on Linux) to port 9090 of the machine running Kodi it is possible to send and receive raw json data to/from Kodi. {{see also|SSH}}


==== HTTP ====
==== HTTP ====
A simple way of manually sending HTTP requests containing a JSON RPC request to XBMC is using the [http://chrome.google.com/extensions/detail/fhjcajmcbmldlhcimfajhfbgofnpcjmb Simple REST Client] extension for Google's Chrome/Chromium browser. It allows defining an URL and the HTTP request type ('''POST''' is what we need). The actual JSON RPC request can be defined in the '''Data''' field and then sent to XBMC.
A simple way of manually sending HTTP requests containing a JSON-RPC request to Kodi is using the [http://chrome.google.com/extensions/detail/fhjcajmcbmldlhcimfajhfbgofnpcjmb Simple REST Client] extension for Google's Chrome/Chromium browser. It allows defining a URL and the HTTP request type ('''POST''' is what we need). The actual JSON-RPC request can be defined in the '''Data''' field and then sent to Kodi.
 
== Development ==
=== Dharma (10.0) ===
==== Supported features of JSON RPC 2.0 ====
* Method calls (with or without parameters) over HTTP or TCP
* Server-side (XBMC) announcements (over TCP port 9090)
* by-name parameters
 
==== Unsupported features of JSON RPC 2.0 ====
* support for by-value OR by-position parameters
* "params" must always be an array (by-position) or an object (by-value) but never a simple type
* Client-side announcements (XBMC returns an error response)
* Bulk requests (XBMC returns a parse error response)
 
=== Eden (11.0) [WIP] ===
==== Additionally supported features of JSON RPC 2.0 ====
* Client-side announcements (methods can be called without the "id" field which will result in the execution of the method without returning a response) [http://github.com/xbmc/xbmc/commit/625699dcd724b771c327b2b1d1e018b8bf91b11c 625699dcd724b771c327]
* Bulk requests (multiple method calls can be sent as an array in a single json rpc request; all methods are executed and the response contains all responses of the bulk request in an array) [http://github.com/xbmc/xbmc/commit/605dbbc542e61c888be46b0d4114ce73b00e14d0 605dbbc542e61c888be4]
* Default JSON output in compact format ([[Advancedsettings.xml#.3Cjsonrpc.3E|Advanced Settings]] option to disable compact json output) [http://github.com/xbmc/xbmc/commit/20e18ee556b324da8f836ec9eb6678840297d7d7 20e18ee556b324da8f83]
* support for by-value OR by-position parameters [http://github.com/xbmc/xbmc/commit/774b8868ee59a1778ad5eeac7d3d712bb2585aed 774b8868ee59a1778ad5]
* "params" must always be an array (by-position) or an object (by-value) but never a simple type [http://github.com/xbmc/xbmc/commit/774b8868ee59a1778ad5eeac7d3d712bb2585aed 774b8868ee59a1778ad5]
 
=== General improvement areas ===
There are about 3 different state returns, that are subtly different, if we want to return player state just reuse State method?
 
Why are there 2 VideoPlayer and AudioPlayer namespaces when they are an arbitrary distinction? Both are handled by the same functions and require extra processing to check the caller used the right namespace.
 
Same for VideoPlaylist and AudioPlaylist, both map directly to AVPlaylist. The third Playlist namespace contains create and destroy commands, implying there is no difference between Audio and Video playlists
 
Use objects for all parameter values, as per JSON 2.0 spec.
Current functions not using an object for parameters
<pre>
AVPlayerOperations.cpp
CAVPlayerOperations::SeekTime
CAVPlayerOperations::SeekPercentage


PicturePlayerOperations.cpp
CPicturePlayerOperations::Zoom


AVPlaylistOperations.cpp
== External links ==
CAVPlaylistOperations::Play
* [http://jsonrpc.org/spec.html JSON-RPC 2.0 specification]
* [http://tools.ietf.org/html/draft-zyp-json-schema-03 A JSON Media Type for Describing the Structure and Meaning of JSON Documents (Draft 03)]


PlaylistOperations.cpp
CPlaylistOperations::Destroy
CPlaylistOperations::Remove      Remote ambiguity about parameter type


AudioLibrary.cpp
CAudioLibrary::GetAlbum        albumid should be genreid


XBMCOperations.cpp
[[Category:JSON-RPC]]
CXBMCOperations::StartSlideshow
CXBMCOperations::Log
</pre>

Latest revision as of 05:47, 20 May 2022

JSON-RPC Pages
Main JSON-RPC Page
- v8 (Krypton)
- v10 (Leia)
- v12 (Matrix)
- v13 (Nexus)
- v14 (Omega)
Examples
All JSON-RPC Pages
Home icon grey.png   ▶ Development ▶ JSON-RPC API


JSON-RPC is a HTTP- and/or raw TCP socket-based interface for communicating with Kodi. It replaces the deprecated HTTP API, and offers a more secure and robust mechanism in the same format. It is based upon the JSON-RPC 2.0 specification.

Each method in the interface can have different security needs which means one client may be allowed to only control playback while another can only read and manipulate the library. In version 2 (first stable) and 4 all clients are granted full authority but will later be forced to ask for privileges and the user of Kodi will have to grant said client access. The design of JSON-RPC is that most methods should behave roughly the same and maintain consistency while hiding the mechanics of Kodi from the client creator.

In Kodi JSON-RPC can be accessed over a variety of transports and has been designed from the ground up to be flexible to allow control over new transports easily. Some of the transports have different limitations which will be enforced upon the interaction over that transport. As an example HTTP transports allow response and downloading of files while the raw TCP transport allows response and notifications (events and information Kodi sends to its clients). Depending on the client's needs it will choose one (or many) of the available transports.


Enabling JSON-RPC

Since the interface is available on many transports enabling it depends on the transport.

  • Python: Always enabled
  • HTTP: In System/Settings/Network/Services activate Allow control of Kodi via HTTP (see Enabling the webserver)
  • TCP: In System/Settings/Network/Services activate Allow programs on this system to control Kodi for localhost access only and Allow programs on other systems to control Kodi for access from other computers as well

Note: The EventServer is a different interface for sending remote keypresses to Kodi, and must be enabled separately, some programs may use both interfaces.

Transports & Functionalities

Transports

Python

The Python transport can only be used by Kodi addons through the executeJSONRPC method provided by the xbmc python library. As it must be available to every addon in an Kodi installation it must not be enabled or disabled by the user.

HTTP

The HTTP transport can be used by third-party applications running on the same machine as Kodi or on a different machine which can access the machine running Kodi using the HTTP protocol. Because this transport allows applications outside Kodi to control Kodi, it has to be manually enabled (see Enabling JSON-RPC) by the user.

POST

Third-party applications can access Kodi's JSON-RPC API by sending JSON-RPC requests embedded in HTTP POST requests to the following URL

http://<your-ip>:<your-port>/jsonrpc

Starting with Frodo nightly builds it is mandatory to set the HTTP header field Content-Type: application/json

GET

Third-party application can access Kodi's JSON-RPC API by sending JSON-RPC requests embedded in a HTTP GET parameter called request. The JSON-RPC request must be URL encoded and sent to the following URL

http://<your-ip>:<your-port>/jsonrpc?request=<url-encoded-request>

TCP

The TCP transport can be used by third-party applications running on the same machine as Kodi or on a different machine which can access the machine running Kodi using the TCP protocol. Because this transport allows applications outside Kodi to control Kodi it has to be manually enabled (see Enabling JSON-RPC) by the user. Once enabled, third-party applications can access Kodi's JSON-RPC API by opening a TCP socket on port 9090 (this port can be configured in the advanced settings file) and sending raw JSON-RPC requests over that socket. Please note that no delimiters are provided in between notifications and/or responses. As such, your client needs to be able to deal with this, eg. by counting and matching curly braces ({}).

WebSocket

The WebSocket transport has been added since Version 5 and can be used by third-party applications running on the same machine as Kodi or on a different machine which can access the machine running Kodi using the Websocket protocol. The supported versions are 8 (draft hybi-10) and 13 (RFC 6455). Because this transport allows applications outside Kodi to control Kodi it has to be manually enabled (see Enabling JSON-RPC) by the user. Once enabled, third-party applications can access Kodi's JSON-RPC API by sending a WebSocket protocol handshake to the following URI

ws://<your-ip>:<configured tcp port>/jsonrpc

It is important to send the handshake on the port of Kodi's TCP server (by default 9090, but this port can be configured in the advanced settings file). After having successfully finished the handshake third-party applications can send WebSocket protocl messages over that connection.

Functionalities

Response

The Response functionality is the only functionality that should be present in every transport available as it describes the functionality to respond to a JSON-RPC request with a valid JSON-RPC response (be it an error message or an actual response).

Notifications

The Notifications functionality includes both server-side (from the server to clients) and client-side (from clients to the server) notifications. A JSON-RPC notification is a valid JSON-RPC request with no id property. Following the JSON-RPC 2.0 specification any JSON-RPC request with no id must be considered as a notification and the receiver must not send a response upon a notification.

In the specific case of Kodi, server-side notifications are used to inform clients about certain events to relieve clients of the need to periodically poll for certain events. Furthermore there are two ways of client-side notifications. Using JSONRPC.NotifyAll it is possible to ask Kodi to relay the message in the JSON-RPC request to all other connected clients. The second way is to send JSON-RPC requests without an id property in case the client does not care about the response (e.g. the method Player.Stop does not return any useful information to the client).

Direct file download

The Direct file download functionality is the ability to directly download files from Kodi by calling Files.Download. In this case the term direct means that the download happens within the JSON-RPC response of the Files.Download request.

Redirected file download

The Redirected file download functionality is the ability to indirectly download files from Kodi by calling Files.PrepareDownload and using the data received in the response to download the file over a different protocol (like HTTP, FTP ...) or another socket. As the Redirected file download is very transport specific, it must be handled separately for every transport supporting it.

Comparison

The following table shows all the available transports and what functionalities they support

Transport Response Notifications Direct file
download
Redirected file
download
Python Yes No No No
TCP Yes Yes No No
HTTP POST Yes No No Yes
GET1 Yes No No Yes
WebSocket1 Yes Yes No No

1 Added in Version 5

API versions

The JSON-RPC API exposed by Kodi is constantly extended to provide better and more functionality to third party applications. For that reason Kodi provides a version information through the JSONRPC.Version method. The rule is that odd version numbers describe an API state, that is not stable and under heavy development whereas even version numbers describe a stable API. Therefore the version number can be used by third-party clients to check if their application might not be fully compatible with the JSON-RPC API exposed by a user's Kodi installation.

Starting with XBMC v12 (Frodo) we started using a new versioning system (<major>.<minor>.<patch>) for the JSON-RPC API. Frodo stable is version 6.0.0 and from now on with every bugfix the <patch> part of the version is increased, with every feature addition to the API, the <minor> version is increased (and the <patch> version reset to 0) and with every backwards incompatible change, the <major> version is increased.

Release JSON-RPC 2.0 specification Transports
API Version Version Name Method calls Notifications
(server-side)
Notifications
(client-side)
Parameters
by-name
Parameters
by-position
Batch requests Python TCP HTTP POST HTTP GET WebSocket
Version 2 10.0 Dharma Yes Yes No Yes No No Yes Yes Yes No No
Version 3 / 4 pre-11 / 11.0 Eden Yes Yes Yes Yes Yes Yes Yes Yes Yes No No
Version 5 / 6 pre-12 / 12.0 Frodo Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 13.0 Gotham Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 13.1 Gotham Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 13.2 Gotham Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 14.0 Helix Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 14.1 Helix Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 14.2 Helix Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 15.0 Isengard Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 15.1 Isengard Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 15.2 Isengard Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 16.0 Jarvis Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 6 16.1 Jarvis Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 8 17.0 Krypton Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Version 10 18 Leia Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes1 Yes
Version 12 19 Matrix Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes1 Yes

1For information requests only, actions require POST

Release JSONRPC.Version
Date Version Codename ["version"]
18 December 2010 10.0 Dharma 2
10 March 2011 10.1 Dharma 2
24 March 2012 11.0 Eden 4
29 January 2013 12.0 Frodo {"major":6,"minor":0,"patch":0}
18 March 2013 12.1 Frodo {"major":6,"minor":0,"patch":3}
03 May 2013 12.2 Frodo {"major":6,"minor":0,"patch":3}
24 December 2013 12.3 Frodo {"major":6,"minor":0,"patch":3}
04 May 2014 13.0 Gotham {"major":6,"minor":14,"patch":3}
05 June 2014 13.1 Gotham {"major":6,"minor":14,"patch":3}
17 August 2014 13.2 Gotham {"major":6,"minor":14,"patch":3}
23 December 2014 14.0 Helix {"major":6,"minor":21,"patch":2}
30 January 2014 14.1 Helix {"major":6,"minor":21,"patch":2}
26 March 2014 14.2 Helix {"major":6,"minor":21,"patch":2}
21 July 2015 15.0 Isengard {"major":6,"minor":25,"patch":2}
16 August 2015 15.1 Isengard {"major":6,"minor":25,"patch":2}
19 October 2015 15.2 Isengard {"major":6,"minor":25,"patch":2}
21 February 2016 16.0 Jarvis {"major":6,"minor":32,"patch":4}
24 April 2016 16.1 Jarvis {"major":6,"minor":32,"patch":5}
05 February 2017 17.0 Krypton {"major":8,"minor":0,"patch":0}
20 March 2017 17.1 Krypton {"major":8,"minor":0,"patch":0}
23 May 2017 17.2 Krypton {"major":8,"minor":0,"patch":0}
24 May 2017 17.3 Krypton {"major":8,"minor":0,"patch":0}
22 August 2017 17.4 Krypton {"major":8,"minor":0,"patch":0}
23 October 2017 17.5 Krypton {"major":8,"minor":0,"patch":0}
14 November 2017 17.6 Krypton {"major":8,"minor":0,"patch":0}
29 January 2019 18.0 Leia {"major":10,"minor":1,"patch":1}
17 February 2019 18.1 Leia {"major":10,"minor":1,"patch":2}
22 April 2019 18.2 Leia {"major":10,"minor":3,"patch":0}
27 June 2019 18.3 Leia {"major":10,"minor":3,"patch":0}
01 September 2019 18.4 Leia {"major":10,"minor":3,"patch":0}
17 November 2019 18.5 Leia {"major":10,"minor":3,"patch":0}
02 March 2020 18.6 Leia {"major":10,"minor":3,"patch":0}
21 May 2020 18.7 Leia {"major":10,"minor":3,"patch":0}
01 June 2020 18.7.1 Leia {"major":10,"minor":3,"patch":0}
14 June 2020 18.7.2 Leia {"major":10,"minor":3,"patch":0}
29 July 2020 18.8 Leia {"major":10,"minor":3,"patch":0}
24 October 2020 18.9 Leia {"major":10,"minor":3,"patch":0}
20 February 2021 19.0 Matrix {"major":12,"minor":2,"patch":1}
10 May 2021 19.1 Matrix {"major":12,"minor":3,"patch":0}
09 October 2021 19.2 Matrix {"major":12,"minor":4,"patch":0}
28 October 2021 19.3 Matrix {"major":12,"minor":4,"patch":0}
04 March 2022 19.4 Matrix {"major":12,"minor":4,"patch":0}
TBA 2022 20.0 Nexus {"major":12,"minor":10,"patch":2}

Documentation

Kodi's JSON-RPC API has been designed to be self-documented i.e. a call to JSONRPC.Introspect results in a JSON-RPC response containing a documentation for all the available methods and data types. While this documentation is very incomplete and partly wrong for version 2 it is provided as a full JSON schema starting with version 3. As the documentation retrieved in that way is always specific to the used version of Kodi, it is (especially for development versions) the best documentation available and should be preferred over the wiki documentation as the latter always documents the API of the latest development.

Debugging

Output format

To be able to support easier debugging of (third-party) development using the JSON-RPC API, the JSON output generated by Kodi can be pretty-printed by setting

<jsonrpc>
    <compactoutput>false</compactoutput>
</jsonrpc>

in the advancedsettings.xml. Default JSON output will be in compact format to minimize sent data (especially useful for mobile devices).

Direct interaction

To be able to test some methods of Kodi's JSON-RPC API, it can be of great help to be able to send a single hand-written JSON-RPC request to Kodi to see its effect and the generated response. Depending on the transport protocol used there are different possibilities to do that:

TCP

With a telnet connection (using PuTTY on Windows or telnet on Linux) to port 9090 of the machine running Kodi it is possible to send and receive raw json data to/from Kodi.

HTTP

A simple way of manually sending HTTP requests containing a JSON-RPC request to Kodi is using the Simple REST Client extension for Google's Chrome/Chromium browser. It allows defining a URL and the HTTP request type (POST is what we need). The actual JSON-RPC request can be defined in the Data field and then sent to Kodi.


External links