I resolved my problem with this code:
<?php
require('routeros_api.class.php');
$API = new routeros_api();
$API->debug = true;
if ($API->connect('111.111.111.111', 'login', 'password')) {
$API->write('/system/script/getall',false);
$API->write('=.proplist=name',false);
$API->write('?name=miapi');
$API->write('/system/script/run',false);
$API->write("=.id=*2");
$API->read(false);
$API->disconnect();
}
?>
This work, i try it with ros v5.2.
I hope that this code can help others persons.
It is good you got it to work.
Unless you left something out, this code is meaningless to your objective:
$API->write('/system/script/getall',false);
$API->write('=.proplist=name',false);
$API->write('?name=miapi');
It requests all the script names where the name = "miapi".
So ROS returns "miapi" if that script exists.
But your code does nothing with that return data.
You can delete those lines or comment them out so you can refer back.
This is what actually runs the script:
$API->write('/system/script/run',false);
$API->write("=.id=*2");
Also, keep in mind that the value of .id can change from device to device and also if you delete the script and re-add it. It all depends on where in the database sequence the script was added.