c# api create hotspot user command

hi,
What is the c# api command to create the hotspot user?

Same as with any other client:

/ip/hotspot/user/add
=name=username
=password=password
=profile=profile1

The exact C# code would depend on which C# client we’re talking about.

hi boen_robot,


Mikrotik RB1100AHx2 1U Router Firewall
RouterOS v5.23
WS 2010

c# api class = http://wiki.mikrotik.com/wiki/API_in_C_Sharp

code =

private void createuserBtn_Click(object sender, EventArgs e)
{
MK mikrotik = new MK(“x.x.x.197”);
if (!mikrotik.Login(“admin”, “123”))
{
MessageBox.Show(“no connect”);
mikrotik.Close();
return;
}
MessageBox.Show(“connect”);

mikrotik.Send(“/ip/hotspot/user/add”);
mikrotik.Send(“=name=999”);
mikrotik.Send(“=password=999”);
mikrotik.Send(“=profile=profile1”);

//MessageBox.Show(“create user”);
mikrotik.Close();
}

result =
connect ok,
create user no,
disconnect ok.

? = Why not create a user… :slight_smile:

Add “false” as a second argument to each method, to ensure all API words are part of the same API sentence.

i.e.

MK mikrotik = new MK("x.x.x.197");
 if (!mikrotik.Login("admin", "123"))
 {
 MessageBox.Show("no connect");
 mikrotik.Close();
 return;
 }
 MessageBox.Show("connect");

 mikrotik.Send("/ip/hotspot/user/add", false);
 mikrotik.Send("=name=999", false);
 mikrotik.Send("=password=999", false);
 mikrotik.Send("=profile=profile1");

 //MessageBox.Show("create user");
 mikrotik.Close();

Thanks
I tried but it does not …
:frowning:

Perhaps you need to explicitly do a Read() too, even if you’re not going to use the results, e.g.

mikrotik.Send("=profile=profile1");
mikrotik.Read();

hi,

not create user.
:frowning:

Looking at the source, it seems this client has a big bug in it… the “false” thing doesn’t really work - it’s ignored. More importantly though, it always finishes the API sentence. But not all is lost. The version without a second argument doesn’t finish the API sentence, oddly enough.

So, in combination with the Read() thing, you should be able to do it with:

MK mikrotik = new MK("x.x.x.197");
 if (!mikrotik.Login("admin", "123"))
 {
 MessageBox.Show("no connect");
 mikrotik.Close();
 return;
 }
 MessageBox.Show("connect");

 mikrotik.Send("/ip/hotspot/user/add");
 mikrotik.Send("=name=999");
 mikrotik.Send("=password=999");
 mikrotik.Send("=profile=profile1", true);
 mikrotik.Read();

 //MessageBox.Show("create user");
 mikrotik.Close();

If even that doesn’t work, I’d highly advise you to use the other C# client - the one at the bottom of the API spec.

hi,

thanks.

not with api, I’m trying to ssh in c#

now hotspot user’s balance can view from client pc

http://forum.mikrotik.com/t/now-hotspot-user-can-see-balance-data-from-status-page/65363/1

I have a C# application where I need to update a usermanager user
I use this code

  		MikrotikApi.Send("/tool/user-manager/user/set");
                MikrotikApi.Send("=name=" + username);
                MikrotikApi.Send("=first-name=" + firstName);
                MikrotikApi.Send("=comment=" + comment);
                MikrotikApi.Send("=email=" + email);
                MikrotikApi.Send("=password=" + password);
                MikrotikApi.Send("=customer=admin", true);

And the code is executed with no error.
Yet nothing gets updated . WHY ??? what did I forget here?

Use the argument “numbers” to target items. Everything else is the new value you want for that user (e.g. if you want to rename a user, you’ll want “numbers” with the current username, and “name” with the new username).

The “numbers” argument I think accepts the username, but if it doesn’t, you’ll need to use the “print” command with a query, to get the user’s ID.

I did it already thanks for the quick reply :smiley:

Goodnight.

I have a question, I am trying to add users through the hotspot what happens is that in this code the winbox does not receive the password, only the created user is displayed, I thought it was the false but the same error still appears.

Thank you.

This is the code

class Program
{
static void Main (string args)
{
MK mikrotik = new MK (“10.10.0.254”);
if (! mikrotik.Login (“itamar”, “12345678”))
{
Console.WriteLine (“The account could not be entered”);
Console.ReadKey ();
mikrotik.Close ();
return;
}
//mikrotik.Send(“/system/identity/getall “);
//mikrotik.Send(”.tag=sss “, true);
mikrotik.Send (”/ ip / hotspot / user / add”);
mikrotik.Send (“= name = user1”, false);
mikrotik.Send (“= password = new2”, false);
mikrotik.Send (“= profile = profile1”, true);
Console.WriteLine (“created user”);

foreach (string h in mikrotik.Read ())
{
Console.WriteLine (h);
}
Console.ReadKey ();
}
}

can we add a new user with time limits?

Good morning, I’m with this error, someone has a solution.
thank you
ErroLogin.jpg