•   
  • 1
  • 11
  • 12
  • 13
  • 14
  • 15(current)
Working JSON RPC API Examples
I am donating an example that I wasn't able to find elsewhere.  Maybe this is obvious to many but I struggled with it for a bit before I found an answer.  I was looking for a way to pass a variable to a JSON RPC call.  All of the examples I found had the string actually programmed into the RPC call.  Here's what I came up with, which works:

                playitem = '"' + piclist[slideIdx] + '"'
                jjson_query = xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Player.Open",   "params":{"item":{"file":%s }},"id":1}' % (playitem)) 

In this example piclist is a list of file names (accessed by URLs) and slideIdx is the index to the item in the list.  This is part of a loop where I pass filenames to JSON RPC to play.

Jeff
Running Kodi with the Mezzmo Kodi addon.  The easy way to share your media. | Service.autostop , CBC Sports and Mezzmo Kodi addon author
Reply
Just in case you are interested...if you would like to pass more variables to a JSON call, you have to do it that way:

 xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"VideoLibrary.Export", "params":{"options": {"actorthumbs": %s, "images": %s, "overwrite": %s}, "id":"1"}}' %(var1, var2, var3))


act = true
img = false
over = true
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"VideoLibrary.Export", "params":{"options": {"actorthumbs": %s, "images": %s, "overwrite": %s}, "id":"1"}}' %(act, img, over))

The order will make the difference which one will be used for %s
Reply
I am trying to get a call to work by searching on the "path" for movies.

I am testing via Firefox, and can get expected results with:

http://127.0.0.1:8080/jsonrpc?request={
    "jsonrpc": "2.0",
    "method": "VideoLibrary.GetMovies",
    "params": {
        "filter": {"field": "path", "operator": "startswith", "value": "plugin://plugin.video.plexkodiconnect.movies/"},
        "sort": { "order": "ascending", "method": "label" },
        "properties": ["title"]
    },
    "id": 1
}

However, I need to have the path include a question mark (which does exist for all Movies in my case), so exactly the same as above, but with additional character at the end of the path:

http://127.0.0.1:8080/jsonrpc?request={
    "jsonrpc": "2.0",
    "method": "VideoLibrary.GetMovies",
    "params": {
        "filter": {"field": "path", "operator": "startswith", "value": "plugin://plugin.video.plexkodiconnect.movies/?"},
        "sort": { "order": "ascending", "method": "label" },
        "properties": ["title"]
    },
    "id": 1
}

This gives no error, but also no results, which is incorrect, as all Movie paths do contain the question mark.

I've tried many variations on encoding the question mark, but I just can't seem to get the expected matches.

Any hints here?
Reply
(2022-10-11, 23:58)kcook_shield Wrote: I am trying to get a call to work by searching on the "path" for movies.

...

However, I need to have the path include a question mark (which does exist for all Movies in my case), so exactly the same as above, but with additional character at the end of the path:

http://127.0.0.1:8080/jsonrpc?request={
    "jsonrpc": "2.0",
    "method": "VideoLibrary.GetMovies",
    "params": {
        "filter": {"field": "path", "operator": "startswith", "value": "plugin://plugin.video.plexkodiconnect.movies/?"},
        "sort": { "order": "ascending", "method": "label" },
        "properties": ["title"]
    },
    "id": 1
}

This gives no error, but also no results, which is incorrect, as all Movie paths do contain the question mark.

I've tried many variations on encoding the question mark, but I just can't seem to get the expected matches.

Any hints here?

Which operating system and file system are you using? A majority of file systems consider a question mark to be a wildcard character, so I'm surprised at your question. With HTTP paths, a question mark normally denotes that a variable and its value are about to follow. Have you tried using "%3F" (sans quotes)?
Headless Linux Kodi box [Ubuntu 16.04.6 LTS Server] | Dedicated Media Server [Ubuntu 16.04.6 LTS Server]
Reply
Thanks for the response, I see the error of my ways.

What I really wanted to search against is field "file" , not "path".

But trying same example with this change produces the "Received value does not match any of the union type definitions" error, which I guess means that field "file" is not searchable like this:

http://127.0.0.1:8080/jsonrpc?request={
    "jsonrpc": "2.0",
    "method": "VideoLibrary.GetMovies",
    "params": {
        "filter": {"field": "file", "operator": "startswith", "value": "plugin://plugin.video.plexkodiconnect.movies/?"},
        "sort": { "order": "ascending", "method": "label" },
        "properties": ["title","file"]
    },
    "id": 1
}

What I am trying to do requires that I start with just a "file" (that does exist) like:

plugin://plugin.video.plexkodiconnect.movies/?mode=play&plex_id=13630&plex_type=movie&filename=12 Angry Men (1957).mp4

And use jsonrpc to search for the related data for this entry, I now see that it does not look like this is possible (search based only on "file")?
Reply
Figured it out, had to use field "filename" (and urlencode the file) :


http://127.0.0.1:8080/jsonrpc?request={
    "jsonrpc": "2.0",
    "method": "VideoLibrary.GetMovies",
    "params": {
        "filter": {"field": "filename", "operator": "is", "value": "plugin%3A%2F%2Fplugin.video.plexkodiconnect.movies%2F%3Fmode%3Dplay%26plex_id%3D13630%26plex_type%3Dmovie%26filename%3D12%20Angry%20Men%20%281957%29.mp4"},
        "sort": { "order": "ascending", "method": "label" },
        "properties": ["title","file"]
    },
    "id": 1
}

This works, thanks for helping me see the issue!
Reply
Ha! Excellent! You beat me to it... LoL. Smile

I was about to write you back and suggest playing around with a different "field" or "sort" enum to see if you got a warmer response from the API. Glad you resolved it!

And I meant to mention URLencode in my last post... I apologize for what was a rather poorly worded suggestion on my part about the hex string for the ? character. I should have elaborated in that post and mentioned URLencode, though clearly you're astute enough to have gone down that path! :-)
Headless Linux Kodi box [Ubuntu 16.04.6 LTS Server] | Dedicated Media Server [Ubuntu 16.04.6 LTS Server]
Reply
Hi,

I don't understand where I am wrong, I send this command:
Quote:curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Export", "params": { "options": { "overwrite": false, "actorthumbs": true, "images": true } }, "id": 1 }' -H 'content-type: application/json;' http://192.168.26.12:8088/jsonrpc
and the nfo is create and the folder .actors but without fanart or poster or any jpeg.
I have no probleme with the interface.

Regards
Reply
(2022-10-16, 15:17)SolidGoti Wrote: Hi,

I don't understand where I am wrong, I send this command:
Quote:curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Export", "params": { "options": { "overwrite": false, "actorthumbs": true, "images": true } }, "id": 1 }' -H 'content-type: application/json;' http://192.168.26.12:8088/jsonrpc
and the nfo is create and the folder .actors but without fanart or poster or any jpeg.
I have no probleme with the interface.

The more details you can provide, the better... and the more likely you'll receive some helpful tips from others. For example: 1) Which operating system are you using? 2) Can you provide an example of the output you are receiving? 3) Which version of Kodi?

A couple of thoughts off-hand...

1) If you're using Kodi v17 or later, you must send API payload via POST method. If Kodi v16 and earlier, use GET.
2) Normally (from my experience) you need to include the username and password in the URL portion of the payload, in order to authenticate the remote call. Are you making the call from localhost?
Headless Linux Kodi box [Ubuntu 16.04.6 LTS Server] | Dedicated Media Server [Ubuntu 16.04.6 LTS Server]
Reply
Is there a way that I can tell when VideoLibrary.RefreshTVShow has finished?

I am using this command:
Code:
curl.exe -s -X POST -d '{"jsonrpc": "2.0", "method": "VideoLibrary.RefreshTVShow", "params": { "tvshowid": 797, "refreshepisodes": true }, "id": "1"}' -H "content-type:application/json" http://USERNAME:[email protected]:8080/jsonrpc
And it returns OK immediately, which isn't a surprise.

But then I have no idea when it's finished, and I don't really want to fire off multiple refreshes without knowing when they're done.


As a note, during the time when the show is refreshing, Library.IsScanningVideo:
Code:
curl -s -X POST -d '{ "jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": {"booleans": ["Library.IsScanningVideo"]}, "id": 1 }' -H 'content-type: application/json' http://USERNAME:[email protected]:8080/jsonrpc
always returns "false". Apparently this only returns "true" when a full library scan is running. Which also isn't a surprise after thinking about it - but I was hoping that it would return "true" during a refresh.
Reply
  •   
  • 1
  • 11
  • 12
  • 13
  • 14
  • 15(current)



Logout Mark Read Team Forum Stats Members Help
Working JSON RPC API Examples0
This forum uses Lukasz Tkacz MyBB addons.