HttpGET Request to a API


i try to acces the kodi api, i tried it this way
the header is application/json

var url = "http%3a%2f%2fkodi%3a1234%40192.168.0.164%3a8023%2fjsonrpc%3frequest%3d"
    var contenttype = "application%2fjson"
    var request = '%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetItem%22%2c+%22params%22%3a+%7b+%22properties%22%3a+%5b%22title%22%2c++%22season%22%2c+%22episode%22%2c+%22rating%22%2c++%22duration%22%2c+%22showtitle%22%2c+%22tvshowid%22%2c+%22thumbnail%22%2c+%22file%22%2c+%22fanart%22%5d%2c+%22playerid%22%3a+1+%7d%2c+%22id%22%3a+%22VideoGetItem%22%7d'
    result = sendHttpGetRequest(url + request)

this dont error.

Invalid URI host: null (authority: null) in meinscript

the browser call is{%22jsonrpc%22:%20%222.0%22,%20%22method%22:%20%22Player.GetItem%22,%20%22params%22:%20{%20%22properties%22:%20[%22title%22,%20%20%22season%22,%20%22episode%22,%20%22rating%22,%20%20%22duration%22,%20%22showtitle%22,%20%22tvshowid%22,%20%22thumbnail%22,%20%22file%22,%20%22fanart%22],%20%22playerid%22:%201%20},%20%22id%22:%20%22VideoGetItem%22}

the REst Client Call is{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title",  "season", "episode", "rating",  "duration", "showtitle", "tvshowid", "thumbnail", "file", "fanart"], "playerid": 1 }, "id": "VideoGetItem"}

i tried this also

    result = sendHttpGetRequest("http://kodi:1234@", "application/json", "{\"jsonrpc\":\"2.0\",\"method\":\"Player.GetItem\",\"params\":{\"properties\":\"[\"title\"]\",\"playerid\":\"1\"},\"id\":\"VideoGetItem\"}")

but a error
**An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.HTTP.sendHttpGetRequest(java.lang.String,java.util.Map,int) on instance: null in meinscript


can please someone help?

Why don‘t you use http:// (and so on) instead of escaping everything?

okay, i changed it and it works.

but now i had another problem my image from the json rpc has this path


this doesnt work

val test =  URLEncoder::encode(fanart, "data:image/jpeg;base64")

any idea how i must encode to write it in a Image item?

Just as a questions: Why don’t you use the HTTP binding instead of doing all the stuff yourself in rules?


there is no special reason for this, I have not yet worked with the http binding.

is it possible there?

do you have an idea how I can solve the problem?

No, I have never used HTTP request in rules. The http binding has an image channel. I think that should work for you.

can you explain how to use it?

Add a url thing (HTTP - Bindings | openHAB), put the host in the baseURL field, add an image channel, put the other parts of the URL in the stateExtension, link the channel to an image item. That should do.

i tried it, the value of the image item is


and the image is not shown, here is the error

Creating request for '{%22jsonrpc%22:%20%222.0%22,%20%22method%22:%20%22Player.GetItem%22,%20%22params%22:%20{%20%22properties%22:%20[%22title%22,%22fanart%22],%20%22playerid%22:%201%20},%20%22id%22:%20%22VideoGetItem%22}/fanart' failed: Conversion = 'j'

i dont know why he adds /fanart at the end of the url.

my baseurl is the completet json call.

Maybe you should describe what you want to achieve in some words. If „fanart“ is added, you typed it somewhere. The binding does not add that.

okay, i call over a json rpc a fanart image of the mediacenter Kodi, i get this with this url

"fanart": "image://http%3a%2f%2f127.0.0.1%3a57578%2f44712%2fImages%2fBackdrop%2f0%3fEnableImageEnhancers%3dTrue%26Tag%3da1bb61a46530de76b18b8b9e544f14b1/"

here is the browser call

{"id":"VideoGetItem","jsonrpc":"2.0","result":{"item":{"fanart":"image://http%3a%2f%2f127.0.0.1%3a57578%2f44712%2fImages%2fBackdrop%2f0%3fEnableImageEnhancers%3dTrue%26Tag%3da1bb61a46530de76b18b8b9e544f14b1/","id":1417,"label":"Das Ende ist der Anfang ist das Ende","title":"Das Ende ist der Anfang ist das Ende","type":"episode"}}}

but this format dont accepted by openhab. i read it must be base64 converted.

now i tried it with the http binding, i get a error in log.


Creating request for '{%22jsonrpc%22:%20%222.0%22,%20%22method%22:%20%22Player.GetItem%22,%20%22params%22:%20{%20%22properties%22:%20[%22title%22,%22fanart%22],%20%22playerid%22:%201%20},%20%22id%22:%20%22VideoGetItem%22}/$.result.item.fanart' failed: Conversion = 'j'

the “$.result.item.fanart” is the fanart in the json request

can me SOMEONE say how to convert my fanart url to BASE64 that i can use it in Openhab?

I did a test with an Image item and how to set it:
the items file contains:

Image MyImage

my rules file conatins:


The result can be displayed e.g. in a sitemap.
To get the base64 encoded string you can run:

base64 YourPNGfile.png

This e.g. can be returned by executeCommandLine or directly do a call to the REST API from there.

That means your fanart variable needs to contain the binary picture that then needs to be base64 encoded. Looks like the only thing that is missing in your case is the call to postUpdate ?