Working JSON RPC API Examples

  Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
anniemartin Offline
Junior Member
Posts: 1
Joined: Aug 2014
Reputation: 0
Post: #31
Good examples are always welcome. It can also be useful putting the responses into json-csv.com to view the output clearly.
find quote
black_eagle Offline
Posting Freak
Posts: 1,815
Joined: Sep 2013
Reputation: 79
Location: East Yorkshire, UK
Post: #32
(2014-06-22 18:28)tonilundin Wrote:  Example for turning off system?

{"jsonrpc": "2.0", "method": "System.Suspend", "id":1}

Using cURL

Code:
curl -s --data-binary '{"jsonrpc": "2.0", "method": "System.Suspend", "id":1}' -H 'content-type: application/json;' http://$xbmcAddress:9001/jsonrpc

Where $xbmcAddress is the IP address of the machine running XBMC, 9001 is the port, and .Suspend may be any of .Suspend .Shutdown .Hibernate or .Reboot

Learning Linux the hard way !!
find quote
pedz Offline
Junior Member
Posts: 5
Joined: Sep 2014
Reputation: 0
Post: #33
I had a heck of a time getting anything to work. I hope this helps others.

To get the list of active players:

Code:
curl --user foo:bar --header 'Content-Type: application/json' --data-binary '{ "id": 1, "jsonrpc": "2.0", "method": "Player.GetActivePlayers" }' 'http://192.168.1.127/jsonrpc'

Response can be something like:

Code:
{"id":1,"jsonrpc":"2.0","result":[{"playerid":2,"type":"picture"}]}

To stop player #2:

Code:
curl --user foo:bar --header 'Content-Type: application/json' --data-binary '{ "id": 1, "jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": 2 } }' 'http://192.168.1.127/jsonrpc'

Response is something like:

Code:
{"id":1,"jsonrpc":"2.0","result":"OK"}

The playerid is what was returned for playerid in the GetActivePlayers.

To start a slideshow:

Code:
curl --user foo:bar --header 'Content-Type: application/json' --data-binary '{ "id": 1, "jsonrpc": "2.0", "method": "Player.Open", "params": {"item": { "path": "/media/PERRY/Picks" } } }' 'http://192.168.1.127/jsonrpc'

Response is:

Code:
{"id":1,"jsonrpc":"2.0","result":"OK"}

In my case, PERRY is the name of a USB stick mounted on a Raspberry Pi and Picks is a directory of JPGs and Videos.

It seems you do not need the --globoff after all when using the --data-binary method.
You need to set --header or you get back HTTP/1.1 415 Unsupported Media Type.
You must have the id if you want to get a response back but you don't if you want to just give a command and assume it works.
The value for "id" is an integer and is used to match up the response that comes back.
The jsonrpc 2.0 is needed or you get an "Invalid Request" back.

My only question left is when can / should you use "GET" instead of "Post" ?

Thank you,
Perry
(This post was last modified: 2014-09-14 20:45 by pedz.)
find quote
VeggieVampire Offline
Junior Member
Posts: 14
Joined: Nov 2014
Reputation: 1
Post: #34
Great examples here is a little more to add to them with just changing the beginning of the string. So no need for typing in usernames and passwords.

//Play a single video from file. change everything in bold.
http://user:pass@xbmcIP:xbmcPort/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"file:///C:/PATH/FILE"}}}
(This post was last modified: 2014-11-07 05:08 by VeggieVampire.)
find quote
barrygordon Offline
Senior Member
Posts: 119
Joined: May 2010
Reputation: 0
Location: Merritt ISland FL
Post: #35
I am just starting to get back to Kodi (XBMC) after being away from it for a few years. I have forgotten too many things (at my age 75, I forget way too much) and could use a little assist. I can still write code in several languages, deal with sockets, and JSON.

I want to use the JSON interface and understand the api as discussed in the wiki. My first preference is to do it over TCP instead of HTTP.

Where do I enable Kodi to accept JSON commands over TCP? What port does Kodi listen at for TCP commands?

If I use the HTTP interface, where do I enble it. Do I have to send a Userid/Password and if so where is that set up in Kodi? A concrete example of an HTTP command would help, it's the userid password issue that bothers me.

All my movies are on a NAS that has SMB capability. The movies are all in mkv format in folders with the movie name under a master folder named movies. The NAS has a network name of Tower. I normally refer to a movie in the following manner: //tower/movies/skyfall/skyfall.mkv for the movie skyfall when I want to play it in a windows based player. In the JSON for player.open what should the item look like? Should it be a file///tower/movies/. . . or SMB://tower/movies/. . . or. Confused

Any and all assistance greatly appreciated
find quote
subcityzero Offline
Junior Member
Posts: 37
Joined: May 2013
Reputation: 0
Post: #36
For 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

For HTTP:

In System/Settings/Network/Services activate Allow control of Kodi via HTTP

When using HTTP request you can give use CURL request sending a username and password as htaccess basic login, example:

Code:
curl --user user:pass https://xyz.com/a

The naming convention about calling a remote file thru SMB is not in my knowledge, but with the above answers I believe I have answered the most of your questions.
find quote
healie Offline
Junior Member
Posts: 1
Joined: Dec 2014
Reputation: 0
Post: #37
Hi all,

could someone please post a working example how to export the video library using curl?
i have tried something like this but it doesn't work.
Code:
curl.exe -i -X POST -d "{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Export\", \"params\": { \"path\": \"d:\\temp\", \"overwrite\": false, \"actorthumbs\": true, \"images\": true    }, \"id\": \"libMovies\"}"  -H "content-type:application/json" http://xbmc:[email protected]:80/jsonrpc rem > NUL 2>&1

thanks by advance
(This post was last modified: 2014-12-22 23:09 by healie.)
find quote
gb160 Offline
Member
Posts: 66
Joined: Oct 2014
Reputation: 0
Post: #38
(2014-11-06 05:40)VeggieVampire Wrote:  Great examples here is a little more to add to them with just changing the beginning of the string. So no need for typing in usernames and passwords.

//Play a single video from file. change everything in bold.
http://user:pass@xbmcIP:xbmcPort/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"file:///C:/PATH/FILE"}}}

Hi I'm using this example to remotely open my cctv streams and it works great...any idea how you attach a custom thumbnail or icon that displays in the osd ?
I've tried hundreds of variations but I'm getting nowhere...the irritating thing is i had this working perfectly a while back, but due to a complete brainfart managed to delete the scripts id written that achieved this.
Checked the wiki and it doesn't seem to cover this scenario.
find quote
thomasdc Offline
Junior Member
Posts: 2
Joined: Mar 2015
Reputation: 0
Post: #39
HI!

i am having problems to start a streaming file (radio)
the file is storred in the music folder on my raspberry pi (openElec)

when i do this:

http://192.168.1.150/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"file://storage/music/StudioBrussel.strm"}}}

it wont start, my xbmc says:

"Playback failed,
one or more items failed to play. check the log file for details."

(but i cant find any log file

can someone help me?
thanks!
find quote
nellie7878 Offline
Junior Member
Posts: 7
Joined: Nov 2014
Reputation: 1
Post: #40
Is it possible to submit a library search query through a JSON command?
find quote
tdhz77 Offline
Senior Member
Posts: 150
Joined: Apr 2009
Reputation: 1
Post: #41
(2015-04-27 04:40)nellie7878 Wrote:  Is it possible to submit a library search query through a JSON command?

http://192.168.1.150/jsonrpc?request={"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": { "start" : 0, "end": 75 }, "properties" : ["art", "rating", "thumbnail", "playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMovies"}
(This post was last modified: 2015-05-16 03:40 by tdhz77.)
find quote
regystro Offline
Junior Member
Posts: 6
Joined: Jan 2014
Reputation: 0
Post: #42
Anyone knows how to set audio delay? (The one you can change by pressing "A" key during video playback).

I've been trying with Input.ExecuteAction {"action":"audiodelay"} but it only shows the audio offset selector on the GUI. Any chance to set and/or get current audio offset value?
I've used JSONRPC.Introspect to get all settings, but haven't found any to change this value.

Thanks in advance.
find quote
axa88 Offline
Senior Member
Posts: 137
Joined: Mar 2015
Reputation: 5
Location: NY USA
Post: #43
(2015-06-04 01:11)regystro Wrote:  Anyone knows how to set audio delay? (The one you can change by pressing "A" key during video playback).

I've been trying with Input.ExecuteAction {"action":"audiodelay"} but it only shows the audio offset selector on the GUI. Any chance to set and/or get current audio offset value?
I've used JSONRPC.Introspect to get all settings, but haven't found any to change this value.

Thanks in advance.

There doesn't appear to be discrete values attainable via json rpc, the same goes for the other slider type UI controls, audio offset, subtitle offset, volume amplification, vertical shift, pixel ratio, brightness, contrast...
I would guess the Input.Action Methods are somehow hooking into the UI.
I for one hope to see it further developed in json, discrete get and set values where applicable.
find quote
ric9887 Offline
Junior Member
Posts: 3
Joined: Jan 2008
Reputation: 0
Post: #44
Is it possibe that anyone can help me with an example of opening a UDP url without making an open request to an .STRM file ?

I would like the player to open UDP://239.1.1.1:10000.
It works fine with an strm file, but I dont really want to have to host a bunch of .strm files really.
Any help would be appreciated.

Regards
Rich

Answered my own question, and seems to work fine :-
http://??.??.??.??/jsonrpc?request={"jsonrpc":"2.0", "id":1, "method": "Player.Open", "params":{"item":{"file":"udp://239.1.1.11:10000"}}}
(This post was last modified: 2015-06-26 11:46 by ric9887.)
find quote
CrsdrNoRemorse Offline
Junior Member
Posts: 4
Joined: Jul 2015
Reputation: 0
Post: #45
Hello,

Can anyone help me with the GUI.GetProperties method? Say I want to recover the "Input" property from the home screen, what would the JSON message be like? I've tried for the last hour, bit I still can't get it to work.

Thanks in advance!
find quote
Post Reply