I am trying to write a c# windows program to manage users. I am having a hard time using the /tool//user-manager/user/set command to reset thier password. What I am getting back is an invalid command error. All other commands work fine but the set commands. It is hard to program without having a complete API manual. I do not know what I am doing wrong. Can other people use the set command?
Can you show your actual code?
When you say other commands… Do you mean remove/enable/disable? Or just “add”? Because with the exception of “add”, other commands require the ID of the item(s) you want to target in the “numbers” argument, and you first need to get with a “print” command.
It’s a common problem for newcomers to want to just specify a number as an identifier or write “find” as part of the set/remove/enable/disable command, which is not how you do it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using mikumlib;
//namespace MKuserman
//{
public class MKuserman
{
private string url = “/tool/user-manager/user/”;
// private string url = “/ip/hotspot/user/”;
private mkusermanager mk;
private string mkserver;
private string mkusername;
private string mkpassword;
public List output;
public MKuserman(string server, string username, string password)
{
mkserver = server;
mkusername = username;
mkpassword = password;
mk = new mkusermanager(mkserver, 8728, mkusername,mkpassword);
mk.Connect();
mk.Login();
}
public bool Login() { return mk.IsConnected(); }
public void Add(string username,string password, string profile)
{
Vouchers tmp = mk.CreateVoucher(profile, username, password);
}
public void Remove(string userid)
{
if (Login())
{
var del = mk.RemoveVoucher(userid);
}
}
public void Setpassword(Vouchers user, string password)
{
if (Login())
{
var cmd = url + “set=numbers=” + user.Id +
“=password=” + password;
mk.Send(cmd, true);
var output = mk.Read();
}
}
public void Setphone(Vouchers user, string phone)
{
if (Login())
{
var cmd = url + “set=numbers=” + user.Id + “=phone=” + phone;
mk.Send(cmd, true);
var output = mk.Read();
}
}
public List Getusers()
{
var info = mk.LoadVouchers();
return info;
}
}
//}
Each call to the Send() method represents one API word.
And each sentence contains multiple words, plus a single empty one. So f.e.
if (Login())
{
mk.Send(url + "set");
mk.Send("=numbers=" + user.Id);
mk.Send("=password=" + password);
mk.Send("");
var output = mk.Read();
}
No error. but did mot set
Looking more closely at the source of mikumlib, the ID you get with its methods doesn’t include the “*”. However, that is required when actually giving the ID to RouterOS.
So make that
mk.Send("=numbers=*" + user.Id);