Skip to content

Instantly share code, notes, and snippets.

@mattmattmatt
Last active June 30, 2022 16:48
Show Gist options
  • Save mattmattmatt/02a3d55bda85d067922115b271392138 to your computer and use it in GitHub Desktop.
Save mattmattmatt/02a3d55bda85d067922115b271392138 to your computer and use it in GitHub Desktop.
I had a hard time finding the documentation about the Kodi or XBMC JSONRPC API and how to make requests from a browser without running into CORS header problems. Kodi luckily supports JSONP-style requests. So if you can only make GET requests and want to circumvent CORS restrictions, use this JSONP snippet.
// npm i --save jsonp
import jsonp from 'jsonp';
var host = 'http://192.168.1.140';
var data = {
'jsonrpc': '2.0',
'method': 'Application.GetProperties',
'params': '[["volume","muted","version"]]',
'id': Math.ceil(Math.random() * 10000)
};
// JSONP GET scheme: /jsonrpc?request=<encodedRequestObject>&jsonp=<jsonpCallbackName>
jsonp(
host + '/jsonrpc?request=' + encodeURIComponent(JSON.stringify(data)),
{},
function(error, data) {
console.log(error, data);
}
);
@mattmattmatt
Copy link
Author

Check if party mode is active

http://kodi.my.home/jsonrpc?request=%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22Player.GetProperties%22%2C%22params%22%3A%5B0%2C%5B%22partymode%22%5D%5D%2C%22id%22%3A127%7D

@MarkMcCormackD8rNode
Copy link

@mattmattmatt
My god, thank you for posting this up!

I was completely stuck trying to get some information from my local Kodi box just for browser React project I'm messing around on. Kept getting CORS issues, found that the CORS fix never got pulled into the Kodi master and then was totally stuck.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment