Making RPC calls to Kodi

Help! as a Glitch newbie (and a JS newbie and nearly everything else) I’m getting stuck trying to get my project to make RPC calls to my Kodi server.

I’m trying to find the Album ID for a Fleet Foxes album. The RPC call works from a browser window, but when I use the same structure in Glitch I get this log entry:

Command sent = {“jsonrpc”:“2.0”,“id”:1,“method”:“AudioLibrary.GetAlbums”,“params”:{“limits”:{“start”:0,“end”:50},“properties”:[“playcount”,“artist”,“genre”,“rating”,“thumbnail”,“year”,“mood”,“style”],“filter”:{“field”:“album”,“operator”:“is”,“value”:“Fleet Foxes”},“sort”:{“order”:“ascending”,“method”:“album”,“ignorearticle”:true}}}

{ FetchError: invalid json response body at http://xx.xx.xx.xx:8080/jsonrpc reason: Unexpected end of JSON input

at /app/node_modules/node-fetch/lib/body.js:48:31

at process._tickCallback (internal/process/next_tick.js:109:7)

name: ‘FetchError’,

message: ‘invalid json response body at http://xx.xx.xx.xx:8080/jsonrpc reason: Unexpected end of JSON input’,

type: ‘invalid-json’ }

I take it that /app/node_modules/node-fetch/lib/body.js is in somebody else’s code?

Any ideas where to start?



I take it the JSON you’re sending doesn’t have the type of quotes like above? As that’s invalid. But yes, node-fetch is a library.

Interesting, Gareth - can you please tell me more? The quotes are inserted by a function called json.stringify (from another library). Most of the code was written by Omertu - I’m just trying to cannibalise it to play albums rather than movies.

the Javascript for the original parameter string looks like this:

var kodiPlayAlbum = function(request, response,param, id) {
var AlbumTitle = request.query.q.trim();
// Build filter to search library for this album

var param = {
limits: { start : 0, end: 50 },
properties: [ “playcount”, “artist”, “genre”, “rating”, “thumbnail”, “year”, “mood”, “style”],
filter: {field: ‘album’, operator: ‘is’, value: AlbumTitle},
sort: { order: ‘ascending’, method: ‘album’, ignorearticle: true}};

console.log (“test param”,param);

console.log(“Album request received to play “” + AlbumTitle + “””);


The browser command line is full of double quotes, like the log entry, and works fine.



It’s probably not the issue then, given the code above, otherwise you’ll be seeing lots of errors in your logs. I just meant that the quotes should be "" not “”, but that’s probably introduced by the forum when you’re pasting in code outside of a code block. It’d be handy if you’re able to share the project you’re using, so we can take a look at the code in context.

I think it is public already - it’s called kodi-ga

Thanks for your help! And thanks for Glitch - great site!



OK, some progress

The Kodi username passwords I stored in Glitch in the .env file included capital letters - because that was how I had set up the Kodi implementation. If I set the username and password in .env to all lower case, my call is executed, or attempted to be executed in Kodi. I can get Kodi to execute a ‘Stop’ RPC (which is pretty simple) but I’m still struggling to get it to execute a ‘GetAlbums’ RPC - log entry below.

Command sent = {“jsonrpc”:“2.0”,“id”:1,“method”:“AudioLibrary.GetAlbums”}
8:45 PM
TypeError: Cannot read property ‘length’ of undefined
8:45 PM
at Fuse._startSearch (/app/node_modules/fuse.js/src/fuse.js:170:23)
8:45 PM
at (/app/node_modules/fuse.js/src/fuse.js:141:10)
8:45 PM
at /app/server.js:306:27
8:45 PM
at process._tickCallback (internal/process/next_tick.js:109:7)
8:45 PM

Still - getting there!


OK, I got it to work - my new code used ‘album’ as a variable instead of ‘albums’, which is what the Kodi json schema says. Thanks Glitch and Omertu!


1 Like

Cool, pleased to hear it!