API PHP on ROS3.20

Dear All,


I tried to read several times the examples on the forum and wiki page how to use the API with PHP, but I’m struggling with the following script and the result I get. What I’m trying to do is the following: I would like to verify if a certain user have been already registered or not on pptp secrets list by the following script:

<?php require('routeros_api.class.php'); $API = new routeros_api(); $API->debug = true; if ($API->connect('192.168.2.12', 'admin', 'admin')) {\ \ $API->write('/ppp/secret/print',false); $API->write('=count-only=',false); $API->write('=where=',false); $API->write('?name=' . "ppp1"); $READ = $API->read(); $ARRAY = $API->parse_response($READ); print_r($ARRAY); $API->disconnect();\ \ } ?>

ppp1 is the user registered and I should find 1 or 0 if it’s registered or not in the secrets list. However as script result I get always 3 which is the total numbers of users registered.
I’m using the 3.20 ROS version.
What am I doing wrong?

Thanks

$API->write(‘?name=’ . “ppp1”);

should actually be:

$API->write(‘=name=’ . “ppp1”);


Also upgrade your routeros to latest to fix many other options

Thanks, but didn’t work. I get the following result


Connection attempt #1 to 192.168.2.12:8278… <<< [6] /login >>> [5/5] bytes read. >>> [5, 39]!done >>> [37/37] bytes read. >>> [37, 1]=ret=e51623bc946de0de5c4fc93cbd24103d <<< [6] /login <<< [11] =name=admin <<< [44] =response=0087af0329a37a612843318805d62598cc >>> [5/5] bytes read. >>> [5, 0]!done Connected… <<< [17] /ppp/secret/print <<< [12] =count-only= <<< [7] =where= <<< [10] =name=ppp1 >>> [5/5] bytes read. >>> [5, 0]!trap >>> [23/23] bytes read. >>> [23, 8]=message=argument error >>> [5/5] bytes read. >>> [5, 1]!done Warning: preg_match_all() expects parameter 2 to be string, array given in /usr/local/www/mkapi/routeros_api.class.php on line 151 Array ( ) Disconnected…


Any suggestion?

you have to use newer RouterOS to use queries. If you check API manual you can clearly see that that feature was introduced in 3.21

http://wiki.mikrotik.com/wiki/API#Queries

Thank you for the suggestion. After update it worked