Edit Mikrotik user profile with PHP API

I am creating a WiFi authentication tool with changes to user profile and guest account, etc.

I can write users to mikrotik and delete users without issue, but I can't find any documentation on editing user profile. I suppose I could just delete it and add a new entry, but that is just inefficient and can create problems with custom keys by row.

I am using class.routeros_api.php and I am on version 6.30

To add a user, do this ...

$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"
));

      

Delete user ...

$response = $api->comm("/tool/user-manager/user/remove",array(
    ".id"               => "*15"
));

      

so I figured editing the user would be something like ...

$response = $api->comm("/tool/user-manager/user/edit",array(
    ".id"               => "*15",
    "username"          => "someotheruser",
    "password"          => "someotherpass"
));

      

However, the error I am getting 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 anyone has done this before and can help with the appropriate syntax for the "/ tool / user-manager / user / edit" command, we would be very grateful.

+3


source to share


1 answer


So, after doing some research on how this thing works, it seems I was just using the wrong command.

The correct way to edit a user on mikrotik is to do the following ...

$api->comm("/tool/user-manager/user/set",array(
    ".id"               => "*14",
    "username"          => "somenewuser"
    "password"          => "somenewpassword",
));

      



In fact, "set" is a way to publish changes for each function. "edit" for multi-line editing.

Special thanks to drew010 for the WinBox idea and the command wiki link.

+5


source







All Articles