Community discussions

MikroTik App
 
liferunner
just joined
Topic Author
Posts: 5
Joined: Fri Dec 05, 2014 2:36 pm

Mikrotik API: Query ONE(single) parameter's value of many

Fri Dec 05, 2014 2:54 pm

Hi everyone,

I did research through the wikis, manuals,forums and so on, but still couldn't find the answer. I want to query single parameter value through the API, but still always receiving mess of tons of parameters. In human query I need:

Get value of security profile ID by security profile name.
Get name of wireless security profile by specific ID.
So on...

As I understood from manual, I am sending:
/interface/wireless/security-profiles/getall
or
/interface/wireless/security-profiles/print
and providing some query arguments for output filtering
?name=DEV
As a result taking ALL parameters for profile DEV, i would like to receive ONE parameter by it's name provided somewhere in query.

Thanks,
Anton
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Mikrotik API: Query ONE(single) parameter's value of man

Sat Dec 06, 2014 1:42 am

I'm not very skilled with the API :), but taking a stab at this...

I think you want to do something like this to get id by name:
/interface/wireless/security-profiles/print
=.proplist=.id
?name=default
And this to get name by id:
/interface/wireless/security-profiles/print
=.proplist=name
?.id=*0
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Mikrotik API: Query ONE(single) parameter's value of man

Sat Dec 06, 2014 4:14 pm

In RouterOS v6.0 and later, you can also use the the "get" command, similarly as you do from terminal, except that you need to explicitly use the argument names, e.g.
/interface/wireless/security-profiles/get
=number=default
=value-name=wpa2-passphrase
(the result is in a property called "ret")

Note also that, as the example above shows, when the menu you're targeting uses names, you don't have to use the ID - you can just use the name directly.


If you want to read several properties of an item at once OR read all items' property of that kind, it's still more efficient to use "print" with ".proplist", as skot shows above.
Last edited by boen_robot on Mon Dec 08, 2014 1:44 pm, edited 1 time in total.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Mikrotik API: Query ONE(single) parameter's value of man

Mon Dec 08, 2014 3:05 am

In RouterOS v6.0 and later, you can also use the the "get" command, similarly as you do from terminal, except that you need to explicitly use the argument names, e.g.
/interface/wireless/security-profiles/get
=number=default
=value-name=wpa2-passphrase
Nice. Is that on the wiki? I couldn't seem to find it anywhere... I wonder if they forgot to add it.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Mikrotik API: Query ONE(single) parameter's value of man

Mon Dec 08, 2014 1:38 pm

They do say that the API closely follows the command line... So this was supposed to be there from day 1, but it wasn't. In earlier versions, get just returns an empty !done, and that's it.

The place where this change should've been present is not the wiki, but the change logs, and we all know how complete those tend to be.
 
liferunner
just joined
Topic Author
Posts: 5
Joined: Fri Dec 05, 2014 2:36 pm

Re: Mikrotik API: Query ONE(single) parameter's value of man

Mon Dec 08, 2014 3:09 pm

Thanks for the reply guys! "proplist" and additional parameters for "get" did the trick.

I am using RouterOS 6.22 and the brick is called Groove 52HPn.

/interface/wireless/security-profiles/print
=.proplist=.id
?name=default
returns
 -> /login
 <- !done=ret=6258d61b871c102bf1a6c231b1ec4e19
 -> /login
 -> =name=admin
 -> =response=00f01307b18cd65dc3bf26ea86350298a8
 <- !done
 -> /interface/wireless/security-profiles/print
 -> =.proplist=.id
 -> ?name=DEV
 <- !re=.id=*F
 <- !done
 -> /interface/wireless/security-profiles/get
 -> =number=DEV
 -> =value-name=supplicant-identity
returns
 -> /login
 <- !done=ret=9ca33ef709665abef763dc0c482ea30d
 -> /login
 -> =name=admin
 -> =response=001b77adadefc356c7094f4b1b31681197
 <- !done
 -> /interface/wireless/security-profiles/get
 -> =number=DEV
 -> =value-name=supplicant-identity
 <- !done=ret=MikroTik
The only thing I missed what "=number" means in case of "get"? There is no such parameter in list of profile properties.

Thanks,
Anton
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Mikrotik API: Query ONE(single) parameter's value of man

Wed Dec 10, 2014 6:52 pm

The only thing I missed what "=number" means in case of "get"? There is no such parameter in list of profile properties.
It is actually referring to the item name instead a number.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Mikrotik API: Query ONE(single) parameter's value of man

Wed Dec 10, 2014 7:00 pm

When you open up a terminal, type the command, and then type "?".

You'll see
<number>
as part of the "get" output.

"number", as well as any argument written with "<" and ">" as above, is an unnamed argument. An argument with a name that can be omitted when using CLI. With the API though, you can't omit it - you must specify it, always.
 
liferunner
just joined
Topic Author
Posts: 5
Joined: Fri Dec 05, 2014 2:36 pm

Re: Mikrotik API: Query ONE(single) parameter's value of man

Thu Dec 11, 2014 12:24 pm

Got it, Thanks!) For me, as a developer, expression "number=DEV" looks a bit confusing :-D