Mikrotik Profile Activation Failing With No Such Command Error in PHP

528 Views Asked by At

So, I have the following function to activate a Profile for a registered user using the RouterOS php library

 public function activateProfile($username)
    {
        $activationQuery = new Query(
            '/tool/user-manager/user/create-and-activate-profile',
            [
                '=user=' . $username,
                '=customer=admin',
                '=profile=profile1',
            ]
        );
        $response = $this->query($activationQuery)->read(false);
        print("Activating Profile...");
        print_r($response);
    }

But I keep getting the error message below

Activating Profile...Array ( [0] => !trap [1] => =message=no such command [2] => !done )
1

There are 1 best solutions below

0
On

Quick Reply

You cannot pass attribute word user, you need to pass the number that identifies the user instead. Better to first create and then create-and-activate-profile as documentation says.

Explanation

RouterOS APi command words closely follow CLI.

Your command word is /tool/user-manager/user/create-and-activate-profile .

Your attributes words are =user,=customer,=profile.

Yo can compare with CLI and wiki from User_Manager, =user= is available

[admin@106] /tool user-manager user> create-and-activate-profile                                    

<numbers> -- List of item numbers
customer -- 
profile -- 



Demostration

/tool/user-manager/user/add
=customer=admin
=disabled=no
=password=test
=shared-users=1
=username=test

<<< /tool/user-manager/user/add
<<< =customer=admin
<<< =disabled=no
<<< =password=test
<<< =shared-users=1
<<< =username=test
<<< 
>>> !done
>>> =ret=*1
>>> 

<<< /tool/user-manager/user/create-and-activate-profile
<<< =numbers=*1
<<< =customer=admin
<<< =profile=a
<<< 
>>> !done
>>>