JSON-RPC API
![]() |
![]() |
![]() |
JSON-RPC Pages |
---|
Main JSON-RPC Page |
- v8 (Krypton) |
- v10 (Leia) |
- v12 (Matrix) |
- v13 (Nexus) |
- v14 (Omega) |
Examples |
All JSON-RPC Pages |
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 |
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} |
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.
See also
External links
- JSON-RPC 2.0 specification
- A JSON Media Type for Describing the Structure and Meaning of JSON Documents (Draft 03)
Examples
These examples take their base from v4. Any that require a higher version will be marked.