• 1
  • 2
  • 3(current)
  • 4
  • 5
  • 15
Working JSON RPC API Examples
#31
Good examples are always welcome. It can also be useful putting the responses into json-csv.com to view the output clearly.
Reply
#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 !!
Reply
#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
Reply
#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"}}}
Reply
#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. Huh

Any and all assistance greatly appreciated
Reply
#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.
Reply
#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
Reply
#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.
Reply
#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!
Reply
#40
Is it possible to submit a library search query through a JSON command?
Reply
#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"}
Reply
#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.
Reply
#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.
Reply
#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"}}}
Reply
#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!
Reply
  • 1
  • 2
  • 3(current)
  • 4
  • 5
  • 15

Logout Mark Read Team Forum Stats Members Help
Working JSON RPC API Examples0