Working JSON RPC API Examples

  Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
SDG72 Offline
Junior Member
Posts: 2
Joined: Aug 2016
Reputation: 0
Post: #91
Seem to be stuck and could use some help, I have managed to get many of the JSON example commands from JSON-RPC_API (wiki) and http://kodi.wiki/view/JSON-RPC_API/Examples working but have noted that for a more complete user navigation some commands seem to be missing or not documented. I have been able to get the attached list of commands verified working, but number entry 0-9 for example does not seem to be documented anywhere.

My goal here is to have a complete set of one way IP navigation commands for a Kodi installation, so I don't have to use a IR remote to control Kodi. And from the attached info you will see that I have many but some key features are still missing. Number entry, TV Guide, TV Channels, and a Fast Forward and Rewind toggle 2x, 4x, 8x, etc. like a RC6 IR remote does would be REALLY nice since it just makes it easier to navigate than individual discrete requests.

Sorry for the length of the post.

Quote:Transport Commands:
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.PlayPause","params":{ "playerid": 1},"id":1} -- play pause
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1,"play":true},"id":1} – play
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1,"play":false},"id":1} -- pause
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0", "method":"Player.Stop","params":{ "playerid":1},"id":1}—stop
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.GoTo","params":{ "playerid":1,"to":"next"},"id":1} – next
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.GoTo","params":{ "playerid":1,"to":"previous"},"id":1} – previous
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":2},"id":1} -- ffwd with speed 2
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":4},"id":1} -- ffwd with speed 4
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":8},"id":1} -- ffwd with speed 8
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":16},"id":1} -- ffwd with speed 16
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":32},"id":1} -- ffwd with speed 32
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":-2},"id":1} -- rwd with speed 2
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":-4},"id":1} -- rwd with speed 4
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":-8},"id":1} -- rwd with speed 8
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":-16},"id":1} -- rwd with speed 16
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetSpeed","params":{"playerid":1,"speed":-32},"id":1} -- rwd with speed 32
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.Seek","params":{ "playerid":1,"value":"smallforward"},"id":1} -- jump forward
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.Seek","params":{ "playerid":1, "value":"smallbackward"},"id":1} -- jump backward

Repeat and Shuffle commands. Note that I only confirmed a return result of OK in Chrome REST app, I did not visually confirm the result on Kodi.
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0","method":"Player.SetRepeat","params":{ "playerid":1,"repeat":"one" },"id":1} -- repeat one
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetRepeat","params":{ "playerid":1,"repeat":"all" },"id":1} -- repeat all
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetShuffle","params":{"playerid":1,"shuffle":true},"id":1} -- shuffle on
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetShuffle","params":{"playerid":1,"shuffle":false},"id":1} -- shuffle false
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Player.SetRepeat","params":{ "playerid":1,"repeat":"off" },"id":1} -- repeat off


Navigation Commands.
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Back", "id": 1} – Back
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Select", "id": 1} – Select
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Left", "id": 1} – left
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Right", "id": 1} – Right
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Up", "id": 1} – Up
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Down", "id": 1} – Down
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Home", "id": 1} – Home
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.info", "id": 1} --Info
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.showOSD", "id": 1} –ShowOSD
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.ContextMenu", "id": 1} -- Context Menu
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.ShowCodec", "id": 1} – Show codec information of the playing item
http://192.168.0.1:8080/jsonrpc?request={"jsonrpc":"2.0","method":"input.executeaction","params":{"action":"pagedown"},"id":1} – Page Down
http://192.168.0.1:8080/jsonrpc?request={"jsonrpc":"2.0","method":"input.executeaction","params":{"action":"pageup"},"id":1} -- Page Up

Additional commands.
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Application.SetVolume","params":{"volume":"increment"},"id":1 } -- volume up
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Application.SetVolume","params":{"volume":"decrement"},"id":1 } -- volume down
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Playlist.GetItems","params":{"properties":["title","album","artist","duration"],"playlistid":1},"id":1} -- get Playlists
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"AudioLibrary.GetAlbums","params":{"properties":["playcount","artist","genre"],"limits":{"end":10,"start":0},"sort":{"order":"ascending","method":"album","ignorearticle":true}},"id":"libAlbums"} -- get Albums
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"music","parameters":["musicdb://1/"] },"id":1} -- activate Geners
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"music","parameters":["musicdb://2/"]},"id":1} -- activate artists
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"music","parameters":["musicdb://3/"]},"id":1} -- activate albums
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"music","parameters":["musicdb://4/"]},"id":1} -- activate songs

System Commands.
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"System.Reboot","id":1} --Reboot
http://192.168.100.13:8080/jsonrpc?request={"jsonrpc":"2.0","method":"System.Shutdown","id":1} –Shutdown
find quote
black_eagle Offline
Posting Freak
Posts: 1,815
Joined: Sep 2013
Reputation: 79
Location: East Yorkshire, UK
Post: #92
Get the available PVR channel groups

PHP Code:
result=$( curl ---data-binary '{"jsonrpc": "2.0", "method": "PVR.GetChannelGroups", "params": {"channeltype" : "tv"}, "id": 1 }' -'content-type: application/json;' http://$xbmcAddress:$xbmcPort/jsonrpc) 

Use jq to get the channel group ID for 'All channels'. Note, you can change this for whatever channels tags you have set up.

PHP Code:
groupid=$(echo $result jq '.result.channelgroups[] | select(.label=="All channels") | .channelgroupid'

Get channel names and numbers for all channels in the group.

PHP Code:
result=$( curl ---data-binary '{"jsonrpc": "2.0", "method": "PVR.GetChannels", "params": {"channelgroupid" : '$groupid',"properties":["channel"]}, "id": 1 }' -'content-type: application/json;' http://$xbmcAddress:$xbmcPort/jsonrpc) 

Start channel '$startchan' playing

PHP Code:
result=$( curl ---data-binary '{"jsonrpc": "2.0", "method": "Player.Open","params":{"item":{"channelid": '"$startchan"'}}, "id": 1}' -'content-type: application/json;' http://$xbmcAddress:$xbmcPort/jsonrpc) 

Learning Linux the hard way !!
(This post was last modified: 2016-09-19 20:13 by black_eagle.)
find quote
SDG72 Offline
Junior Member
Posts: 2
Joined: Aug 2016
Reputation: 0
Post: #93
(2016-09-19 20:10)black_eagle Wrote:  Get the available PVR channel groups

PHP Code:
result=$( curl ---data-binary '{"jsonrpc": "2.0", "method": "PVR.GetChannelGroups", "params": {"channeltype" : "tv"}, "id": 1 }' -'content-type: application/json;' http://$xbmcAddress:$xbmcPort/jsonrpc) 

Use jq to get the channel group ID for 'All channels'. Note, you can change this for whatever channels tags you have set up.

PHP Code:
groupid=$(echo $result jq '.result.channelgroups[] | select(.label=="All channels") | .channelgroupid'

Get channel names and numbers for all channels in the group.

PHP Code:
result=$( curl ---data-binary '{"jsonrpc": "2.0", "method": "PVR.GetChannels", "params": {"channelgroupid" : '$groupid',"properties":["channel"]}, "id": 1 }' -'content-type: application/json;' http://$xbmcAddress:$xbmcPort/jsonrpc) 

Start channel '$startchan' playing

PHP Code:
result=$( curl ---data-binary '{"jsonrpc": "2.0", "method": "Player.Open","params":{"item":{"channelid": '"$startchan"'}}, "id": 1}' -'content-type: application/json;' http://$xbmcAddress:$xbmcPort/jsonrpc) 

Thanks Black Eagle

I'm new to Linux and Kodi and I am having trouble getting these to work! Here is how I have tested the commands I posted above. One was I used Chrome using the "Simple REST Client" option, and was able to get the strings I posted to show a result in a working Kodi machine that was set static and to port 8080. "I sent these in the form in which you see them posted" and got a result.

I have also used a program like Putty, called "Hercules" to send just the IP strings portion of the commands I'm testing to a Kodi test machine on a static IP and to port 9090 which from what I have read is an open TCP socket, and this has been one of the easiest options, I can open a TCP socket of an IP on a port of my choosing and hold it open while I send IP test strings without the http://IPaddress/port/ in front. Example:
PHP Code:
/jsonrpc?request={"jsonrpc":"2.0","method":"AudioLibrary.GetAlbums","params":{"properties":["playcount","artist","genre"],"limits":{"end":10,"start":0},"sort":{"order":"ascending","method":"album","ignorearticle":true}},"id":"libAlbums"} -- get Albums 
and got a result on the Kodi machine.

So with that said I tried to test the portions that I'm seeing as the TCP command only, so no "http://ipaddress/port" Example, I cut and pasted this:
PHP Code:
result=$( curl ---data-binary '{"jsonrpc": "2.0", "method": "PVR.GetChannels", "params": {"channelgroupid" : '$groupid',"properties":["channel"]}, "id": 1 }' -'content-type: application/json;' 
and sent it to a Kodi machine via Hercules and Chrome with the http://IPaddress/port/jsonrp/ in front, but got no results.

As stated I'm new to Linux and Kodi and hope you can help walk me through these. I tend to poke and prod until I get things to work if you follow me! Thanks!
find quote
alireza44907 Offline
Junior Member
Posts: 3
Joined: Nov 2016
Reputation: 0
Post: #94
Dear All
I want to play a folder that is in USB connected to XBMS.
I tried all the commands that are posted but none of them work.
Can anyone tell me how It can be done?
Thanks
find quote
alireza44907 Offline
Junior Member
Posts: 3
Joined: Nov 2016
Reputation: 0
Post: #95
Found it:

http://192.168.1.7:8080/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"directory":"media/<NAME OF FLASH>/<NAME OF FOLDER>"}}}

It must be paid attention that Uppercase and lowercase letters are important
find quote
VeggieVampire Offline
Junior Member
Posts: 14
Joined: Nov 2014
Reputation: 1
Post: #96
Found a great way to see what's playing on your device.

Code:
curl -s --user foo:bar --header 'Content-Type: application/json' --data-binary '{    "jsonrpc": "2.0",    "method": "Player.GetItem","params": {"properties": [ "file"],"playerid":1},"id": "VideoGetItem"}' 'http://127.0.0.1:8080/jsonrpc'| python -m json.tool

output:
Code:
{
    "id": "VideoGetItem",
    "jsonrpc": "2.0",
    "result": {
        "item": {
            "file": "/PATH/FILE",
            "label": "TITLE",
            "type": "unknown"
        }
    }
}
find quote
life02 Offline
Junior Member
Posts: 2
Joined: Dec 2016
Reputation: 0
Post: #97
Trying to get the Player.open to play a video by label or title using the example from the first page:

Code:
//Play a single video from file
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"Media/Big_Buck_Bunny_1080p.mov"}}}

I have tried the following and neither work:
Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"label":"Big Buck Bunny"}}}
and
Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item"{"title":"Big Buck Bunny"}}}


If I check the now playing (if the file is playing) with:
Code:
http://192.168.15.117/{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "season", "episode", "duration", "showtitle", "tvshowid", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 1 }, "id": "VideoGetItem"}

I see the title and label of file":"Media/Big_Buck_Bunny_1080p.mov is "Big Buck Bunny".

Is there any way to get Player.Open to work with label or title?[/code]
find quote
Happyoldguy Offline
Junior Member
Posts: 6
Joined: Jan 2017
Reputation: 0
Post: #98
Life02
I have the same issue, i want to play based on title or label. I get the error not a valid param. But according to the wiki you should be able to play based on an item in the db as you listed. Is this a bug or am I missing something too?
find quote
jonib Offline
Senior Member
Posts: 100
Joined: Mar 2006
Reputation: 2
Post: #99
(2017-01-01 22:56)Happyoldguy Wrote:  I have the same issue, i want to play based on title or label. I get the error not a valid param. But according to the wiki you should be able to play based on an item in the db as you listed. Is this a bug or am I missing something too?
As far as I know and the JSON-RPC Wiki you need to provide a path or a video id (movieid or episodeid) to play a video. A title or a label is not a unique identifier so there could be 10 videos with the same name.
To be able to use the title do a search to get the id, then use that in the open method.

jonib

XBMC2, EventGhost plugin. [Image: flattr-badge-large.png]
find quote
Happyoldguy Offline
Junior Member
Posts: 6
Joined: Jan 2017
Reputation: 0
Post: #100
(2017-01-02 01:14)jonib Wrote:  
(2017-01-01 22:56)Happyoldguy Wrote:  I have the same issue, i want to play based on title or label. I get the error not a valid param. But according to the wiki you should be able to play based on an item in the db as you listed. Is this a bug or am I missing something too?
As far as I know and the JSON-RPC Wiki you need to provide a path or a video id (movieid or episodeid) to play a video. A title or a label is not a unique identifier so there could be 10 videos with the same name.
To be able to use the title do a search to get the id, then use that in the open method.

jonib

Thanks Jonib
I do see that in the JSON-RPC Wiki. what about tagging? I'm working on IFTTT with Google assistant and would like to say "Ok Google" I want to watch <movie name>. I'm working on a python script to handle the GET from IFTTT and process the the suggestion you had.

Thanks for the input.
find quote
jonib Offline
Senior Member
Posts: 100
Joined: Mar 2006
Reputation: 2
Post: #101
(2017-01-02 04:04)Happyoldguy Wrote:  what about tagging?
Not sure what you are asking, but VideoLibrary.GetMovies can be used to find a movie based on name and tags (and other meta data)

jonib

XBMC2, EventGhost plugin. [Image: flattr-badge-large.png]
find quote
life02 Offline
Junior Member
Posts: 2
Joined: Dec 2016
Reputation: 0
Post: #102
(2017-01-02 04:04)Happyoldguy Wrote:  
(2017-01-02 01:14)jonib Wrote:  
(2017-01-01 22:56)Happyoldguy Wrote:  I have the same issue, i want to play based on title or label. I get the error not a valid param. But according to the wiki you should be able to play based on an item in the db as you listed. Is this a bug or am I missing something too?
As far as I know and the JSON-RPC Wiki you need to provide a path or a video id (movieid or episodeid) to play a video. A title or a label is not a unique identifier so there could be 10 videos with the same name.
To be able to use the title do a search to get the id, then use that in the open method.

jonib

Thanks Jonib
I do see that in the JSON-RPC Wiki. what about tagging? I'm working on IFTTT with Google assistant and would like to say "Ok Google" I want to watch <movie name>. I'm working on a python script to handle the GET from IFTTT and process the the suggestion you had.

Thanks for the input.

Happyoldguy, yeah that's exactly what I was trying to do without making an intermediary script for mapping name to id.

jonib, Thanks, I'll look into VideoLibrary.GetMovies.
find quote
Happyoldguy Offline
Junior Member
Posts: 6
Joined: Jan 2017
Reputation: 0
Post: #103
(2017-01-02 07:12)life02 Wrote:  
(2017-01-02 04:04)Happyoldguy Wrote:  
(2017-01-02 01:14)jonib Wrote:  As far as I know and the JSON-RPC Wiki you need to provide a path or a video id (movieid or episodeid) to play a video. A title or a label is not a unique identifier so there could be 10 videos with the same name.
To be able to use the title do a search to get the id, then use that in the open method.

jonib

Thanks Jonib
I do see that in the JSON-RPC Wiki. what about tagging? I'm working on IFTTT with Google assistant and would like to say "Ok Google" I want to watch <movie name>. I'm working on a python script to handle the GET from IFTTT and process the the suggestion you had.

Thanks for the input.

Happyoldguy, yeah that's exactly what I was trying to do without making an intermediary script for mapping name to id.

jonib, Thanks, I'll look into VideoLibrary.GetMovies.

Ok so last night I dabbled with VideoLibrary.GetMovies and this seems to work to get me the file of the movie by title. Now I need to see how to make this work. If you come up with something please let me know. If I get the solution Ill let you know here.

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc": "2.0", "params": {"sort": {"order": "ascending", "method": "title"}, "filter": {"operator": "is", "field": "title", "value": "<movie title here>"}, "properties": ["title", "art", "file"]}, "method": "VideoLibrary.GetMovies", "id": "libMovies"}
find quote
Happyoldguy Offline
Junior Member
Posts: 6
Joined: Jan 2017
Reputation: 0
Post: #104
Ok guys, im working with a friend and we now can tell kodi to watch a movie and it will list movies with same title, so men and black men and black 2 men in black 3 and let you select by the id of the movie. It is very alpha and hopefully will release the code and a set up soon.
find quote
Happyoldguy Offline
Junior Member
Posts: 6
Joined: Jan 2017
Reputation: 0
Post: #105
Hey guys sorry been under the weather, i will get a git updated soon with instructions.
(This post was last modified: 2017-01-17 15:40 by Happyoldguy.)
find quote
Post Reply