Help Please - Shell command to play channel on Kodi

Hi,

I have a curl command to play a live TV channel in Kodi.

  1. This variation runs successfully from the command line, but does not validate in configuration.yaml:
    Command line:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"channelid":46}}}' http://192.168.x.xxx:8080/jsonrpc

Error from the configuration.yaml:

incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 63, column 46:
     ... s: curl -X POST -H "Content-Type: application/json" -d '{"jsonrp ... 
  1. This variation validates in configuration.yaml:
curl -X POST '{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"channelid":46}}}' -H 'content-type:application/json;' http://192.168.x.xxx:8080/jsonrpc

But does not run from the command line:

curl: (3) nested brace in URL position 57:
{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"channelid":46}}}
                                                        ^
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}

Can anyone offer any suggestions?

You need the quotes in the string, so you have to escape them in yaml.

curl -X POST '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"Player.Open\",\"params\":{\"item\":{\"channelid\":46}}}' -H 'content-type:application/json;' http://192.168.x.xxx:8080/jsonrpc

Basically, if you need the " symbol in the message, add a \ to it and it will be part of the message instead of used as a yaml syntax character.

Your curl command there is just sending a chunk of JSON to an API end point. Doing that with a RESTful command would be more elegant than a shell command. Something like

rest_command:
  kodi_channel:
    url: http://192.168.x.xxx:8080/jsonrpc
    method: post
    content_type: application/json
    payload: '{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"channelid":46}}}'
1 Like

Thanks @stibbons , this is a much cleaner approach.