set command returns !done but does not alter values?

Hello,

I am trying to set a firewall rule with the API but it does not work, my code is:

                        mikrotik.Send("/ip/firewall/filter/set");
                        mikrotik.Send("?chain=variables");
                        mikrotik.Send("?comment=config_template");
                        mikrotik.Send("=content=fux", true);

the API returns “!done”, but the value is not changed, is there any way to debug this and see why it’s not working? am I doing something fundamentally wrong here? /ip/firewall/filter/print is working fine though…

Thanks & Cheers
Freundschaft

The “set” command (in all menus!) doesn’t work that way, although to be fair, I wish it did.

You need to write the ID(s) explicitly with the “numbers” argument. To get the IDs, you can use “print” while specifying a query THERE, e.g.

                        mikrotik.Send("/ip/firewall/filter/print");
                        mikrotik.Send("?chain=variables");
                        mikrotik.Send("?comment=config_template", true);

                        //Read the response and store the value of "=.id=" in variable "Id" here

                        mikrotik.Send("/ip/firewall/filter/set");
                        mikrotik.Send("=numbers=" + Id);
                        mikrotik.Send("=content=fux", true);

oh alright, thank you very much. that’s not very intuitive indeed :frowning:
Maybe we could submit a request to change this behavior?
It’ also a little confusing that the command returns a ‘!done’ from the Mikrotik device, I’d expected an error message.

Cheers & Best Regards
Freundschaft

What RouterOS version are you using? AFAIK, newer versions (think 5.** and later) do give out error messages. Then again, I haven’t tried doing this in a while, so maybe it’s a regression.

Maybe we could submit a request to change this behavior?

There’s a checkbox at the top when you write a new topic/reply about sending this to MikroTik’s support…

I have the newest RouterOS Version 6.1

I have ticked the checkbox and submitted this thread to the support team.

EDIT:
btw, your suggestion worked like a charm, thank you very much :slight_smile:

my colleague just notified me that there has been a change in the new firmware version 6.2 has made some changes that could also effect the way I can retrieve values from the API, any news about this?

The only change (s)he could be reffering to is

*) console - global variables now are common to all users and are
available to all users with at least “read,write,test,policy” policy;

Which would mean you should be able to set values with the API and access them from scripting and vice-versa… which is what you’d think would’ve been the case before, except it’s only now that way.