Community discussions

MikroTik App
 
User avatar
ionas
just joined
Topic Author
Posts: 11
Joined: Tue May 05, 2015 9:41 pm
Location: Nicosia
Contact:

Call global function via API

Wed Aug 24, 2016 6:46 pm

Can I call (run) a global function, already set in the router, via API?

I have set a global function (AddWallgardenDeletionScheduler) that takes 2 parameters but when I try to call it from API doesn't seem to find it. (Doesn't give an error - it's as if it was never been set)

From terminal I can call it like this:

$AddWallgardenDeletionScheduler rulename=<name> ruleip=<ip>

from script I can call it like this:

:global AddWallgardenDeletionScheduler
$AddWallgardenDeletionScheduler rulename=<name> ruleip=<ip>

but via API it cannot find it anyway i tried.

Even if I simply set a global variable like

:global myName "Ionas"

it cannot even read it's value by :log warning [$myName] via API

P.S. I can only print the function or variable using /system script environment print

thx!
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Call global function via API

Thu Aug 25, 2016 2:07 am

I don't think there's a way.

You could however call "/execute" and inside the script, run the variable, i.e.
/execute
=script=$AddWallgardenDeletionScheduler rulename=<name> ruleip=<ip>
 
User avatar
ionas
just joined
Topic Author
Posts: 11
Joined: Tue May 05, 2015 9:41 pm
Location: Nicosia
Contact:

Re: Call global function via API

Fri Aug 26, 2016 5:21 pm

Thx for your response!

I tried that but again no luck!

Unfortunately any script that you run via the API, cannot use (find) any global variables which is very peculiar. If you run the same script from a terminal it can use the global variable just fine but if you run it via the API it doesn't.

The official response from Mikrotik support to this was:

>Hello,
>
>Unfortunately it is not possible. API is for configuration management and monitoring not running and writing scripts.
>
>Best regards,
>Maris
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Call global function via API

Fri Aug 26, 2016 6:15 pm

To be able to access variables (in general), the user you access the router with needs to have both read and write policies... and I think the "policy" policy as well. Anything less will not be able to access variables in any fashion.

If you're not willing to give up this security, I'd suggest you translate your script into API calls or at least boil it down to a single "execute" call where the source contains the actual values (that you'll replace before making the call).

Who is online

Users browsing this forum: No registered users and 24 guests