Edit Mikrotik User Profile With PHP API
So after some research into how this thing actually works, it appears I was just using the wrong command.
The correct way to edit a user on the mikrotik is to do the following...
$api->comm("/tool/user-manager/user/set",array(
".id" => "*14",
"username" => "somenewuser"
"password" => "somenewpassword",
));
In fact, "set" is the way you post edits for every feature. "edit" is for multi-line editing.
Special thanks to drew010 for the WinBox idea and the link to the commands wiki.
![zgr024](https://i.stack.imgur.com/POHPB.jpg?s=256&g=1)
zgr024
I enjoy spending time with family and friends. I also enjoy long walks on the beach and wish for world peace Oh, wait... wrong show
Updated on June 04, 2022Comments
-
zgr024 about 2 years
I'm building a WiFi authentication tool with user profile edit and guest credentials, etc.
I can write users to the mikrotik and remove users without an issue, but I can't find any documentation on editing the user profile. I suppose I could just remove it and add a new record, but that is just inefficient and may create issues with user keys down the line.
I'm using class.routeros_api.php and I'm on version 6.30
To add a user is done like so...
$response = $api->comm("/tool/user-manager/user/add",array( "customer" => "admin", "username" => "guest_user", "location" => "Guest", "first-name" => "Guest", "last-name" => "1", "password" => "somepw", "shared-users" => "1", "copy-from" => "00:00:00:00:00:00" ));
Deleting a user...
$response = $api->comm("/tool/user-manager/user/remove",array( ".id" => "*15" ));
so I figured editing a user would be something like...
$response = $api->comm("/tool/user-manager/user/edit",array( ".id" => "*15", "username" => "someotheruser", "password" => "someotherpass" ));
However, the error I'm receiving is...
<<< [28] /tool/user-manager/user/edit <<< [8] =.id=*14 <<< [14] =username=someotheruser <<< [19] =password=someotherpass >>> [5/5] bytes read. >>> [5, 35]!trap >>> [26/26] bytes read. >>> [26, 8]=message=unknown parameter >>> [5/5] bytes read. >>> [5, 1]!done
If someone has done this before and can assist with the appropriate syntax for the "/tool/user-manager/user/edit" command, it would be greatly appreciated.
-
drew010 almost 9 yearsI don't have access to my Mikrotik test router right now but either the edit command or one of the parameters you are passing is not valid. To figure out what commands and parameters are available, connect via WinBox, open a terminal window and type
/tool/user-manager/user [TAB]
and it will list the available commands. You can then get the parameter list by typing the command and[TAB]
again. -
drew010 almost 9 yearsHere is an example for the built in users:
[admin@demo] > /user edit [TAB]
shows:admin root john number value-name
, then doing/user edit admin [TAB]
shows:address comment group name password value-name
which are the parameters you can set for editing the useradmin
. Hope that helps for now. These then can be translated to API commands and parameters you can use in your code. -
zgr024 almost 9 yearsBut that doesn't give me the syntax for the API on what to pass as the second parameter
-
zgr024 almost 9 yearsI can edit...
caller-id, first-name, phone, username, caller-id-bind-on-first-use, ip-address, random-password, wireless-enc-algo, comment, last-name, reg-key, wireless-enc-key, customer, location, registration-date, wireless-psk, email, password, & shared-users
but the syntax for the API is still unknown
-
-
drew010 almost 9 yearsYup I just found that
set
is the proper command too :) edit is for multi-line editing on the terminal: wiki.mikrotik.com/wiki/Manual:Console#General_Commands