.net user manager api

Hi, cay you say me why I can add users to user manager using this .net code
mk.Send(“/tool/user-manager/user/add”, False)
mk.Send(“=customer=admin”, False)
mk.Send(“=user=a”, False)
mk.Send(“=password=a”,True)

but I can’t remove users using this code
mk.Send(“/tool/user-manager/user/remove”, False)
mk.Send(“=customer=admin”, False)
mk.Send(“=user=a”, True)


All of them runs ok in routeros terminal.

Thank you and excuse my english.

Err, no. You don’t remove users that way, not even from terminal.

In terminal, you remove users like

/tool user-manager user remove [find customer=admin user=a]

Notice the “[” and “]”. This means you’re making another command, the returned value of which will be given to the first.

With the API, you need to “manually” do that other command first, and put the result into the appropriate argument. The appropriate argument being usually called “numbers” (you can verify by typing “?”, and seeing which arguments have “<” and “>” around them).

The “find” command doesn’t (yet?) support queries though, so you must use “print” instead, and again, with queries, e.g.

mk.Send("/tool/user-manager/user/print", False)
 mk.Send("?customer=admin", False)
 mk.Send("?user=a", False)
 mk.Send("?#&",True)

Get the answers from that, and then

mk.Send("/tool/user-manager/user/remove", False)
 mk.Send("=numbers=" + num, True)

(Where “num” is a string containing a comma separated list of all “.id” values)

Excuse me but if I write in the terminal this commands they work:

[admin@MikroTik] > /tool user-manager user remove
a b c d e f g test numbers
[admin@MikroTik] > /tool user-manager user remove a
[admin@MikroTik] >


Regards

If you remove just by username, yes. That’s allowed. In any menu where items can be identified by name, you can use the name.

But in your above example, you wanted to remove a user only if its customer is also a match, and THAT is not allowed from terminal without an inner “find” command.

If you have the username, you can just supply that to numbers, e.g.

 mk.Send("/tool/user-manager/user/remove", False)
 mk.Send("=numbers=a", True)

Your answer is perfect to me. I need only add and remove users to the user manager.

Thanks a lot.

Regards.