Community discussions

MikroTik App
 
User avatar
BrianHiggins
Forum Veteran
Forum Veteran
Topic Author
Posts: 702
Joined: Mon Jan 16, 2006 6:07 am
Location: Norwalk, CT
Contact:

API For Each?

Fri Dec 11, 2015 11:10 pm

goal, single API command that matches and set parameters on multiple items

A couple of example commands that I want to work, but don't...

/radius/set
=src-address=1.2.3.4
?service=PPP

/queue/tree/set
=limit-at=1000
=max-limit=10000
?parent=ParentQueue


Any idea how to do this without first doing something like this and getting all the IDs listed:
/radius/print
=.proplist=.id
?service=PPP

then looping through the results and running something that looks like this (non denominational psudo code syntax):

For Each $ID In IDlist

/radius/set
=src-address=1.2.3.4
=.id=$ID

Next

executing one API command to update a group of settings is clearly more efficient than the way shown that I've actually gotten to work, particularly when there may be 50-100 IDs to update on some of the loops that I run through.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: API For Each?

Sat Dec 12, 2015 12:12 am

Even in CLI, you need two commands. Just because you write them on a single line doesn't mean there aren't two of them being executed.

In CLI, you use
/queue tree set [find where parent=ParentQueue] limit-at=1000 max-limit=10000
which first does "/queue tree find where parent=ParentQueue" and then gives the return value of that to the "numbers" argument at "/queue tree set".

It's the same thing with the API, but more explicit.

If, in the future, you could do from CLI
/queue tree set limit-at=1000 max-limit=10000 where parent=ParentQueue
that's when
/queue/tree/set
=limit-at=1000
=max-limit=10000
?parent=ParentQueue
will become valid, and equivalent of that.

(That's a feature request for MikroTik though)


Some API clients, like the one from my signature, try to abstract this away so that from the outside, it feels like a single call, but on a protocol level, it just can't be done. RouterOS itself doesn't support that.

Who is online

Users browsing this forum: No registered users and 66 guests