Closed RavenWing71 closed 4 years ago
With New Release (6.45.6) I can't log in to MikroTik via API. the new API protocol is needed.
Also here same problem. Can not login using API and this NuGet after RouterOS update...
Can someone write how we should connect now? ApiSsl, ApiSsl_v2? Is it still possible to connect by username and password?
ConnectionFactory.CreateConnection(TikConnectionType.Api_v2) is your friend ;-)
... will update WIKI soon ...
D
@danikf Thanks for the fast reply.
I tried TikConnectionType.Api_v2 already prior to writing here. The result is the same: 'invalid user name or password (6)'.
using (ITikConnection connection = ConnectionFactory.OpenConnection(TikConnectionType.Api_v2, mikrotikGateway.Server, mikrotikGateway.Port, mikrotikGateway.Username, mikrotikGateway.Password))
User can login to winbox though.
Are there any requirements special from the router side for this to work?
I used the api_v2 and worked for me on Mikrotik 6.45.6
ITikConnection connection;
connection = ConnectionFactory.CreateConnection(TikConnectionType.Api_v2);
connection.ReceiveTimeout = 5000;
connection.SendTimeout = 5000;
connection.Open(txtIP.Text, txtUsername.Text, txtPassword.Text);
this.Text = Title + " - " + connection.ExecuteScalar("/system/identity/print");
@raminrajabi thanks for the example. Unfortunately the result is the same as before. I even tried creating new user with full rights on router, still the same problem. RouterOs version is 6.45.6 too, nuget is latest, tik4net v3.4.0
Is API allowed in mikrotik configuration? (ip/services/api) Is API allowed from your machine? (IP filter in ip/services/api) Is API port accessible from the machine? (do you use the right port? default 8728) What about encoding? (exotic characters in username / password) Are you 100% sure you are connecting to the mikrotik router you expected?
In the mikrotik log there are records like this: login failure for user 'X' from 'IP' via api I also checked if api is enabled, firewall etc. so answers would be: Yes Yes Yes only English characters are present in username/password, no encoding is set and needed Yes
Strange :/ last guess: Any ip subnet limitation on user or api service?
Nope, no subnet limitations both on user and api service. Tried on another Mikrotik (test device) and this works like you've said. Before the RouterOs update it worked with both api and api_v2.. after the update on test device it doesn't work with api and it works ok with api_v2 TikConnectionType.. Strange but it is way it is.. Thanks for your help.
@tomidix it magically started working, so this is closed, right?
New version of login (back api and api_ssl) will work for both old and new version of mikrotik.
With RouterOS v6.45 out now, please document the change to Api_V2. If no where else, then here: https://github.com/danikf/tik4net/wiki/CRUD-examples-for-all-APIs. But a note on the Wiki front page would help those of us who already have working code that works no more.