In magento I want to create soap api user by code .
Also assign its role programmatically .
Will create on event observer .
Create your role from admin .
Check its ID after successful creation .
Add this code according to your requirements :
$userapi = Mage::getModel('api/user')
->setData(array(
'username' => '[email protected]',
'firstname' => 'nikhil',
'lastname' => 'ravindran',
'email' => '[email protected]',
'api_key' => 'myp@ssw0rd',
'api_key_confirmation' => 'myp@ssw0rd',
'is_active' => 1,
'user_roles' => '',
'assigned_user_role' => '',
'role_name' => '',
'roles' => array(1) // your created custom role
));
$userapi->save();
$userapi->setRoleIds(array(1)) // your created custom role
->setRoleUserId($userapi->getUserId())
->saveRelations();
Hope it helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With