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

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

I’m not very skilled with the API :slight_smile:, 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

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.

Nice. Is that on the wiki? I couldn’t seem to find it anywhere… I wonder if they forgot to add it.

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.

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

It is actually referring to the item name instead a number.

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.

Got it, Thanks!) For me, as a developer, expression “number=DEV” looks a bit confusing :smiley: