Request: cURL and Postman examples for simple JSON-RPC commands (e.g. up, down...)
#1
Would some kind soul please reply with specific examples of how to execute a simple command like Input.Up
Quote:{
  "description": "Navigate up in GUI",
  "permission": "Navigate",
  "type": "method",
  "params": [],
  "returns": {
    "type": "string"
  }
}
using cURL at a command line and using Postman, please and thank you? 

I'm trying to teach myself JSON-RPC. If I could see how to run a single command using cURL at the command prompt or using Postman, it would help me greatly. If I can see how to write just one command that actually works, then I can figure out how to write many more on my own. 

I'm not asking for a fish or even tackle... just some guidance on how to bait my hook.
Reply
#2
man its been so long ive almost forgot how to make a simple command.

start by reading something on the web about json 2.0

then the kodi wiki
http://kodi.wiki/?title=JSON-RPC_API
There you can read about how to send messages.

Then read the latest spec
http://kodi.wiki/view/JSON-RPC_API/v8
There you can read about what goes in a message

And finally here's an example to get the volume
http://localhost:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["volume"]}, "id": whatever}
paste that in the browser of a machine running kodi and see what happens.

then compare the request and the response to the volume documentation in the spec...
that's may be a good way to start i suppose
Reply
#3
Thank you, Axa88,

Believe it or not, I'd already read all of the KODI Wiki entries on JSON-RPC, including the documentation of every command and the handful of examples before I made my original post. Contrary to what you'd expect, reading them wasn't enough for me to grasp what I'm trying to learn.

I'm not trying to run commands on the same computer running KODI. My instance of KODI is running under Ubuntu on an Intel NUC, so I could use terminal and run the commands there if I wanted to. However, that won't teach me how to run the commands on a remote computer. My goal is to run the commands under cURL and/or Postman on a Windows PC on the same network so that I can test the commands. This way I'll know the exact syntax of commands that can be run successfully on a remote computer. 

Thanks again.
Reply
#4
Postman is a GUI tool that lets you build, test and run JSON (and other) commands for cURL (and others). 

I have a JSON command (Input.Up) that works successfully in Postman: 
  Method: POST
  Address: 192.168.1.83:8080/jsonrpc
  Body: {“jsonrpc”: “2.0”, “method”: “Input.Up”, “id”: 1}
  Type: JSON (application/json)

Image

It does what I want and returns a success message ({“id”:1,“jsonrpc”:“2.0”,“result”:“OK”}).

If I click the Code button by the right margin, it gives me several ways to see the code that Postman is generating. If I choose cURL it gives me this code:

curl -X POST 
http://192.168.1.83:8080/jsonrpc 
-H ‘Cache-Control: no-cache’ 
-H ‘Content-Type: application/json’ 
-H ‘Postman-Token: 82ec87fb-667f-a0fe-182e-9621199274ae’ 
-d ’ {“jsonrpc”: “2.0”, “method”: “Input.Up”, “id”: 1}’

Image
When I try to use that code at a Windows command prompt, it doesn’t work.

Image

How can I generate a code snippet that I can run from a Windows command prompt that will work?

What is the single-line equivalent of my code that works in Postman that will work at the Windows command prompt?
Reply
#5
sorry. dont know anything about cURL or why anyone would use it but try this:
 
Code:
-i -X POST -d "{"jsonrpc": "2.0", "method": "Input.Up", "id": 1}" -H "content-type:application/json" http://username:password@ipaddress:portnumber/jsonrpc
Reply
#6
(2018-01-15, 17:59)soonerlater Wrote: I'm not trying to run commands on the same computer running KODI. My instance of KODI is running under Ubuntu on an Intel NUC, so I could use terminal and run the commands there if I wanted to. However, that won't teach me how to run the commands on a remote computer. My goal is to run the commands under cURL
Year old post, but Google brought me here and this is an issue more and more people will start running into soon.

Below is the syntax @axa88 was looking for. This works on Kodi v18.1 (Leia), with JSON-RPC v9. It transmits a command via curl, using HTTP protocol (POST method). This works in Linux and should also work under Windows 10 if you have the Linux shell installed that Microsloth makes available.

BASH:
curl -X POST -H "content-type:application/json" http://xxx.xxx.xxx.xxx:8080/jsonrpc -d '{"jsonrpc":"2.0","id":1,"method":"System.EjectOpticalDrive"}'

The command above will open your DVD drive door. Run from the command line, it will return a status from the server, such as:

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

Obviously, change the IP address, port (default=8080), and specific command. There is a list of compatible commands here.

Note the "-d" preceding the JSON command is relevant and the command will fail if you don't use it. The "-X POST -H" at the beginning of the line applies to Ubuntu distros. YMMV on other Linux variants, but it will likely work (I'd try it as-is on another distro before reading the man page on curl). -X forces the POST method and -H tells curl it is sending HTTP packets. You need those too.

Answer to your question on executing "Input Up" (command reference found here):

BASH:
curl -X POST -H "content-type:application/json" http://xxx.xxx.xxx.xxx:8080/jsonrpc -d '{"jsonrpc":"2.0","id":1,"method":"InputUp"}'

If you are bothered by curl displaying its response from the Kodi server, you may silence curl's output like this:

BASH:
curl -s --output /dev/null -X POST -H "content-type:application/json" http://xxx.xxx.xxx.xxx:8080/jsonrpc -d '{"jsonrpc":"2.0","id":1,"method":"InputUp"}'

Note: The process above uses Kodi's HTTP server to talk to it (default port 8080); not to be confused with the WebSocket port (default 9090).
Headless Linux Kodi box [Ubuntu 16.04.6 LTS Server] | Dedicated Media Server [Ubuntu 16.04.6 LTS Server]
Reply

Logout Mark Read Team Forum Stats Members Help
Request: cURL and Postman examples for simple JSON-RPC commands (e.g. up, down...)0