danikf / tik4net

Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Apache License 2.0
174 stars 93 forks source link

I'm trying to create command as /PPP/Secret set ... but got replied message "no such command" #14

Closed klhsu closed 7 years ago

klhsu commented 7 years ago

Hi danikf

At first I like to say thank you for developed this good api for managing routerOS very easily. I have an issue as following, hope you can help me how to do.

I've created some accounts for VPN user accounts,I write some code for a function to disable ppp user account, I have test in terminal console in my routerOS as

ppp secret set [find name=a1@openminds.com.tw] disable=yes

It works fine after command executed in terminal console.

my c# code with tik4net command as bellow:

ITikCommand cmd = connection.CreateCommandAndParameters("/ppp/secret/set find[name=" + username + "] disable=yes"); cmd.ExecuteNonQuery();

the username is a variable for ppp user name that I want to disable with.

but the message be shown after execute command : no such command.

Do you have any idea to tell how to perform the command by CreateCommand() method ?

I really appreciate your instructions.

Albert Hsu

danikf commented 7 years ago

Hi, it is not problem of the API, but problem of mikrotik API syntax. See http://wiki.mikrotik.com/wiki/Manual:API for details.

Your code should be like this:

var updateCommand = Connection.CreateCommandAndParameters("/ppp/secret/set",
       "disabled", "yes",
        TikSpecialProperties.Id, username);
 updateCommand.ExecuteNonQuery();

REMARKS: using names instead of real IDs is possible only for some entities.

Enjoy, D