Kodi Community Forum

Full Version: POST request to turn off
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
After updating libreelec on raspberry pi3, the line that turned off the device stopped working:
json:
getURL('http://IP:PORT/jsonrpc?request={"jsonrpc":"2.0","method":"System.Shutdown","id":1}');
What should be the post request for shutdown in the new version?
or better to set up an old version of libreelec with an old version of kodi?
can't see string in my post
getURL('http://IP:PORT/jsonrpc?request={"jsonrpc":"2.0","method":"System.Shutdown","id":1}');
(2018-10-04, 18:15)2054you Wrote: [ -> ]can't see string in my post
Fixed. Smile
Somehow the syntax selection went wrong. Just enter the type of code applicable in a syntax tag, in this case json.
Remove everything after the question mark from the url. Change the method from getURL to whatever the POST equivalent is in the language you're using. Set the type of request to "application/json". Take the JSON (everything after "request=") and set that as the POST body.
getURL('http://IP:PORT/jsonrpc?request={"jsonrpc":"2.0","method":"System.Shutdown","id":1}');
Quote:Remove everything after the question mark from the url
getURL('http://IP:PORT/jsonrpc?');
Quote:Change the method from getURL to whatever the POST equivalent is in the language you're using
$_POST('http://IP:PORT/jsonrpc?');
Quote:the type of request to "application/json"
$_POST('http://IP:PORT/application/json');
Quote:Take the JSON (everything after "request=") and set that as the POST body.
$_POST('http://IP:PORT/application/json{"jsonrpc":"2.0","method":"System.Shutdown","id":1}');

this does not work, I've to turn off the updated kodi hosts by turning off the power, it's the only way
PS. what version of Kodi should I install to make my queries work as before?
Remove the '?' from the url
It looks like you're using PHP. If so, that's not how you use $_POST, and the URL's you created are not how you create a POST request.

If you're wanting to POST from PHP, look here. Then go back and look at my previous posts.
However, if you're trying to use a button or form to turn it off, then you should look at how to post using JavaScript.
(2019-01-06, 22:13)MrTarantula Wrote: [ -> ]It looks like you're using PHP
yes
not a programmer, use this in the project of home automation
(2019-01-06, 22:13)MrTarantula Wrote: [ -> ]look here.
tried to use something like that, but to no avail
thanks anyway
Are you getting any error messages?
(2019-01-07, 10:54)ncarthy Wrote: [ -> ]Are you getting any error messages?
yes
Quote:Fatal error: Function name must be a string in /var/www/modules/scripts/scripts.class.php(150) : eval()'d code on line 1
That error is likely a problem with the mix of ' and " parenthesis in line one.

If you want simple PHP control of Kodi then no need to re-invent the wheel. Have a look in GitHub at how other people are using PHP to control Kodi. Here is an example: https://github.com/KiboOst/php-Kodi-jsonAPI … its just the first item in a google search for "Kodi api PHP" so there will be plenty more examples around the web for you.
(2019-01-08, 19:28)ncarthy Wrote: [ -> ]That error is likely a problem with the mix of ' and " parenthesis in line one.

If you want simple PHP control of Kodi then no need to re-invent the wheel. Have a look in GitHub at how other people are using PHP to control Kodi. Here is an example: https://github.com/KiboOst/php-Kodi-jsonAPI … its just the first item in a google search for "Kodi api PHP" so there will be plenty more examples around the web for you.
I don't want to re-invent the wheel, all I want is to replace one goodworking (before useless updates) string
Quote:getURL('http://IP:8080/jsonrpc?request={"jsonrpc":"2.0","method":"System.Shutdown","id":1}');
with another, that's all
is there a solution how to turn off kodi/libreelec by POST request using php?
tired of restoring backups due to shutdown by power off devices
Look at the code repository ncarthy posted above, specifically the How-to section of the README:
Quote: 
  • Download the class/phpKodi-api.php on your server.
  • Include it in your script.
  • Start it with your device IP.
  • You can use a local IP ('192.168.1.120'), dyndns ('mydynname.ddns.net'), and include pass/port ('user:pass@IP:Port'), regarding if you use your script locally or on a web server.

Include it in your PHP like this:

php:
require($_SERVER['DOCUMENT_ROOT']."/path/to/phpKodi-api.php");
$_Kodi = new Kodi($IP);
if (isset($_Kodi->error)) die($_Kodi->error);

Then use it like this:

php:
$_Kodi->shutdown();
Pages: 1 2