Working JSON RPC API Examples
#1
While trying to figure out the JSON RPC API I tried to find some examples, and have learned that in the past in other languages that examples are extremely powerful for the learning process. So seeing as there isn't much out there to my knowledge as far as working examples, I figured I would put some on here and hope it helps someone. Maybe if other could contribute we could sticky this and help out newer users of the API.

So here is a few of mine.

Some setup information here, this is setup on a basic wired network, with a Raspberry Pi having an IP Address of 192.168.15.117. There are a few things you have to do to get this working the way that I have done. They require steps 3 and 4 here.

Then these are just pasted into the browser of another computer on the same network for testing purposes.

Playlist.GetPlaylists

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc": "2.0", "id": 1, "method": "Playlist.GetPlaylists"}

Returns
Code:
{"id":1,"jsonrpc":"2.0","result":[{"playlistid":0,"type":"audio"},{"playlistid":1,"type":"video"},{"playlistid":2,"type":"picture"}]}

This is just simply a return of the current playlists created and used, as PlaylistID and Type.

--

Files.GetDirectory

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Files.GetDirectory","params":{"directory":"Media","media":"video"}}

Return Example
Code:
{"id":1,"jsonrpc":"2.0","result":{"files":[{"file":"Media/Big_Buck_Bunny_720.strm","filetype":"file","label":"Big_Buck_Bunny_720.strm","type":"unknown"},{"file":"Media/Big_Buck_Bunny_1080p.mov","filetype":"file","label":"Big_Buck_Bunny_1080p.mov","type":"unknown"}],"limits":{"end":2,"start":0,"total":2}}}

Basically just a listing of the media type you requested in the Directory you requested. In the call "Media" is our path, and video is our media type.

--

Player.Open

This one can work a few ways. You can do a slideshow of images from a Directory, file, or play a video from file. I am sure there is more methods for this, but you will have to go read the documentation for further information.
Code:
//Slideshow of Images from a Directory "Images"
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"directory":"Images/"}}}

This plays a slideshow containing all the images in the "Images" directory. The slash may or may not be required. But this works.

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"}}}

This plays the video "Big_Buck_Bunny_1080p.mov" from the Media folder found on the Pi.

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"playlistid":1},"options":{"repeat":"all"}}}

This plays the playlist corresponding to playlistid 1. It also continuously repeats the items at the end of the playlist.

Note: After some discussion, a single file cannot be applied a repeat option. It may accept it but it will not apply it to a single video. Repeating at time of writing requires a Playlist.

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

--

Playlist.Clear

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Playlist.Clear","params":{"playlistid":1}}

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

This clears a playlist you create. This is identified by playlistid in params. Pretty simple.

--

Playlist.Add

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Playlist.Add","params":{"playlistid":1,"item":{"file":"Media/Big_Buck_Bunny_1080p.mov"}}}

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

This adds the file to the playlist with the corresponding playlistid. In this case, Big Buck Bunny is being added to playlistid 1. You can repeat this as many times as needed (not sure if there is a limit..?) to create a playlist.

--

These are what I have encountered so far. I know I had some troubles getting this to work at first because there was no example usage. So I hope these can help others in the future to get going on their projects.
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average


Messages In This Thread
Working JSON RPC API Examples - by Pghpunkid - 2013-03-01, 21:23
RE: Working JSON RPC API Examples - by ndxtg - 2013-03-16, 01:00
RE: Working JSON RPC API Examples - by darwin - 2013-05-25, 03:51
RE: Working JSON RPC API Examples - by Tolriq - 2013-04-29, 20:19
RE: Working JSON RPC API Examples - by jonib - 2013-05-27, 14:33
RE: Working JSON RPC API Examples - by roscoe - 2013-07-02, 13:07
RE: Working JSON RPC API Examples - by yallah - 2013-10-31, 14:51
RE: Working JSON RPC API Examples - by yallah - 2013-10-31, 17:42
RE: Working JSON RPC API Examples - by yallah - 2013-11-01, 00:06
RE: Working JSON RPC API Examples - by yallah - 2013-11-01, 00:28
RE: Working JSON RPC API Examples - by yallah - 2013-11-01, 00:38
RE: Working JSON RPC API Examples - by pedz - 2014-09-14, 20:37
RE: Working JSON RPC API Examples - by gb160 - 2015-02-18, 15:07
RE: Working JSON RPC API Examples - by healie - 2014-12-22, 21:31
RE: Working JSON RPC API Examples - by tdhz77 - 2015-05-16, 03:40
RE: Working JSON RPC API Examples - by axa88 - 2015-06-04, 03:56
RE: Working JSON RPC API Examples - by axa88 - 2015-07-16, 03:18
RE: Working JSON RPC API Examples - by axa88 - 2015-07-27, 03:13
RE: Working JSON RPC API Examples - by axa88 - 2015-07-27, 09:59
RE: Working JSON RPC API Examples - by axa88 - 2015-09-07, 07:41
RE: Working JSON RPC API Examples - by axa88 - 2015-10-16, 20:56
RE: Working JSON RPC API Examples - by LeeJS - 2015-10-09, 23:48
RE: Working JSON RPC API Examples - by wollk - 2015-10-23, 22:19
RE: Working JSON RPC API Examples - by atailo - 2015-11-02, 04:42
RE: Working JSON RPC API Examples - by Razze - 2015-11-02, 16:00
RE: Working JSON RPC API Examples - by atailo - 2015-11-02, 18:55
RE: Working JSON RPC API Examples - by atailo - 2015-11-03, 23:59
RE: Working JSON RPC API Examples - by Ouchie - 2016-03-05, 21:25
RE: Working JSON RPC API Examples - by _BJ1 - 2015-11-29, 20:55
RE: Working JSON RPC API Examples - by Razze - 2015-11-29, 23:32
RE: Working JSON RPC API Examples - by _BJ1 - 2015-11-30, 21:07
RE: Working JSON RPC API Examples - by Tolriq - 2015-11-30, 21:31
RE: Working JSON RPC API Examples - by Tolriq - 2016-01-27, 21:17
RE: Working JSON RPC API Examples - by atailo - 2016-02-23, 15:10
RE: Working JSON RPC API Examples - by B3rt - 2016-03-07, 04:28
RE: Working JSON RPC API Examples - by Razze - 2016-03-07, 14:48
RE: Working JSON RPC API Examples - by B3rt - 2016-03-07, 14:54
RE: Working JSON RPC API Examples - by curti - 2016-03-07, 23:21
RE: Working JSON RPC API Examples - by juju37 - 2016-03-18, 11:34
RE: Working JSON RPC API Examples - by Tolriq - 2016-03-18, 11:48
RE: Working JSON RPC API Examples - by juju37 - 2016-03-18, 12:22
RE: Working JSON RPC API Examples - by atailo - 2016-04-29, 19:21
RE: Working JSON RPC API Examples - by agb2 - 2018-03-26, 17:11
RE: Working JSON RPC API Examples - by agb2 - 2018-04-04, 11:37
RE: Working JSON RPC API Examples - by rmg9 - 2016-06-27, 14:48
RE: Working JSON RPC API Examples - by SDG72 - 2016-09-19, 19:48
RE: Working JSON RPC API Examples - by SDG72 - 2016-09-25, 03:05
RE: Working JSON RPC API Examples - by life02 - 2016-12-27, 00:44
RE: Working JSON RPC API Examples - by jonib - 2017-01-02, 01:14
RE: Working JSON RPC API Examples - by jonib - 2017-01-02, 04:35
RE: Working JSON RPC API Examples - by life02 - 2017-01-02, 07:12
RE: Working JSON RPC API Examples - by jez500 - 2017-01-20, 09:46
RE: Working JSON RPC API Examples - by B3rt - 2017-01-29, 23:06
RE: Working JSON RPC API Examples - by Wimpie - 2017-01-30, 03:03
RE: Working JSON RPC API Examples - by B3rt - 2017-01-30, 11:22
RE: Working JSON RPC API Examples - by ronie - 2017-01-30, 03:19
RE: Working JSON RPC API Examples - by ronie - 2017-01-30, 11:34
RE: Working JSON RPC API Examples - by B3rt - 2017-01-30, 11:48
RE: Working JSON RPC API Examples - by B3rt - 2017-01-30, 15:54
RE: Working JSON RPC API Examples - by isdito - 2017-03-10, 02:00
RE: Working JSON RPC API Examples - by ednt - 2017-05-22, 10:50
RE: Working JSON RPC API Examples - by ednt - 2017-05-22, 11:33
RE: Working JSON RPC API Examples - by ednt - 2017-05-22, 16:52
RE: Working JSON RPC API Examples - by petou - 2017-08-29, 16:23
RE: Working JSON RPC API Examples - by petou - 2017-08-29, 16:28
RE: Working JSON RPC API Examples - by Razze - 2017-08-29, 18:51
RE: Working JSON RPC API Examples - by MKANET - 2017-09-09, 10:11
RE: Working JSON RPC API Examples - by petou - 2017-09-09, 13:06
RE: Working JSON RPC API Examples - by MKANET - 2017-09-10, 02:23
RE: Working JSON RPC API Examples - by petou - 2017-09-10, 03:06
RE: Working JSON RPC API Examples - by MKANET - 2018-07-03, 18:58
RE: Working JSON RPC API Examples - by MKANET - 2018-09-23, 21:23
RE: Working JSON RPC API Examples - by nissse - 2018-11-23, 17:21
RE: Working JSON RPC API Examples - by HTGeek - 2019-04-06, 00:48
RE: Working JSON RPC API Examples - by lysyi - 2019-08-13, 06:36
RE: Working JSON RPC API Examples - by HTGeek - 2019-08-13, 21:31
RE: Working JSON RPC API Examples - by lysyi - 2019-08-13, 22:00
RE: Working JSON RPC API Examples - by HTGeek - 2019-08-13, 22:39


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