Tell me more ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

For an extension I need to create an api user programmatically using php. I use the following code:

 $apiKey = '12345678';
 $user = Mage::getModel('api/user');
    $user->setData(array(
    'username' => 'api_consumer',
    'firstname' => 'fist',
    'lastname' => 'last',
    'email' => '[email protected]',
    'new_api_key' => $apiKey,
    'api_key_confirmation' => $apiKey,
    'is_active' => 1,
    'user_roles' => '',
    'assigned_user_role' => '',
    'role_name' => '',
    'roles' => array($role->getId())
    ));
    $user->save()->load($user->getId());

When I look in the database the api_key field is not filled, it has the value 'NULL'.

Is it possible to persist the api key?

I madfe a casing mistake, above code works, but I changed

'new_api_key' => $apiKey,

to

'api_key' => $apiKey,
share|improve this question

1 Answer

up vote 0 down vote accepted

I just tested your script and it works. The key is saved in the database. Anyway, if that doesn't work for you try adding this in the setData method:

'api_key' => $apiKey,

Instead of

'new_api_key' => $apiKey,
'api_key_confirmation' => $apiKey,
share|improve this answer
Aarrghh, I made a very dumb mistake, a casing issue, I used: $apikey and $apiKey. Thanks for helping! – Henry May 2 at 8:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.