Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
$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();

Source: http://stackoverflow.com/a/20014676https://stackoverflow.com/a/20014676

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

Source: http://stackoverflow.com/a/20014676

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

Source: https://stackoverflow.com/a/20014676

Bounty Ended with 50 reputation awarded by CommunityBot
Source Link

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

Source: http://stackoverflow.com/a/20014676