Page 1 of 1

Using "where" and "find" in MikroTik API

Posted: Mon Jan 19, 2009 5:58 pm
by bokad
I am trying to use the MikroTik API to get the same results as the command line command:
/ip hotspot active print where user=bokad

I have tried:
--------------1--------------------------
$API->write('/ip/hotspot/active/print',false);
$API->write('=where=',false);
$API->write('=user=bokad',true);

--------------2--------------------------
$API->write('/ip/hotspot/active/print',false);
$API->write('=where',false);
$API->write('=user=bokad',true);

--------------3--------------------------
$API->write('/ip/hotspot/active/print',false);
$API->write('=where=user=bokad',true);

#1 and #2 just result in "=message=argument error"
#3 returns a list of all the users, not what I want.

Is there a way to use the where and find commands in the API?

I am using the PHP API found at:
http://wiki.mikrotik.com/wiki/API_PHP_class

Re: Using "where" and "find" in MikroTik API

Posted: Mon Jan 19, 2009 6:44 pm
by cmit
There's no "find" command in API.
You have to print/getall everything and search for the right .id yourself (in the results)...

Re: Using "where" and "find" in MikroTik API

Posted: Mon Jan 19, 2009 8:49 pm
by bokad
Bummer. It's kinda inefficient to transfer an entire list of 1600 logged in users across a slow connection when you just need information on one of them.
Do you know of any plans to implement find or where?
Is there a documentation source for the API with more information than the Wiki?

Thanks.

Re: Using "where" and "find" in MikroTik API

Posted: Tue Jan 20, 2009 9:35 am
by cmit
I don't know of any more information, too. Perhaps writing to support@mikrotik.com can give you more answers...

Re: Using "where" and "find" in MikroTik API

Posted: Sat Feb 28, 2009 9:33 am
by jscoulter
Anymore information on this?
I found the only way to remove a user is to use the .id field.
This does seem quite silly since you know the user name and the IP address, but not the ID, so why make it so you can only remove a user on a field that is not known to you unless you do a print and filter the results? That just adds overhead to the process, and not really all that logical...to me anyway.

Would love to hear any more about this.

Jeremy

Re: Using "where" and "find" in MikroTik API

Posted: Wed Apr 01, 2009 12:34 am
by Chupaka
since 3.21 one can use queries in 'print' API command - it's analogue of 'fint' in CLI

Re: Using "where" and "find" in MikroTik API

Posted: Wed Apr 01, 2009 12:02 pm
by janisk
exactly, queries showed up in 3.21 (3.22) and will stay there for long time, if you are using find, or plan using find, use queries and .proplist to get values you need, to avoid additional parsing of output.

look for more info on wiki API article:
http://wiki.mikrotik.com/wiki/API#Command_description

also, there is news about upcoming changes on how to get OIDs.

Re: Using "where" and "find" in MikroTik API

Posted: Wed Jul 13, 2011 2:08 am
by Percanta
good day
is it possible make this API query /queue simple print where name~"ANDY" ?

Re: Using "where" and "find" in MikroTik API

Posted: Wed Jul 13, 2011 10:12 am
by janisk
yes
/queue/simple/print
?name=ANDY
just to add - you can use queue name directly as value for .id argument to alter/monitor the queue.

Re: Using "where" and "find" in MikroTik API

Posted: Wed Jul 13, 2011 3:55 pm
by Percanta
hi
i tryed that but it doesnt show for example "ANDY LEE"

/queue/simple/print
?name=ANDY -------> /queue simple print where name=ANDY


/queue/simple/print

?(?)(?) ------> /queue simple print where name~"ANDY" this works for "ANDY LEE"

Re: Using "where" and "find" in MikroTik API

Posted: Sat Jul 16, 2011 10:13 am
by Chupaka
unfortunately, you cannot use regular expression matching in API
if you need to match by name prefix and don't want to receive all names to process them on client side, ugly workaround coud be like this:
/some/command/print
?>name=begi[u]n[/u]
?<name=begi[u]o[/u]
?#&