Magento – Fatal error: Uncaught SoapFault exception: [2] Access denied

apisoap

I am trying to login via soap from an external server

$api_url_v2 = "http://www.example.com/api/v2_soap/?wsdl=1";
$username = 'username';
$password = 'password';
$cli = new SoapClient($api_url_v2);
$session_id = $cli->login($username, $password);

The error message I get is Fatal error:

Uncaught SoapFault exception: [2] Access denied

However if I look in the api_user table in magento db, then the lognum column increments by 1 when I have the correct username / password combo… so it seems like the system knows the details are correct, but is giving me access denied.

The users role I have ticked all options for and assigned the role to the user

I can't seem to see many examples of this issue anywhere.

Has anyone come accross this issue, or can you provide any tips to solve?

Best Answer

Please try this connection code:

$client = new SoapClient('http://magentohost/api/v2_soap?wsdl=1');
$session = $client->login('apiUser', 'apiKey');

I took it from the API Guidlines here: http://www.magentocommerce.com/api/soap/introduction.html#Introduction-SOAPAPIVersionv2

I have also used this method on my stores for product retrieval and editting, however, are you on version 1.6.2? I know there is a role setting bug that doesnt allow you to set all roles.

Suggestions: Provide version number, edition & url if possible.


REVISION:

$client = new SoapClient('http://www.comain.co.uk/api/v2_soap?wsdl=1');
$session = $client->login('username', 'apikey');

$result = $client->catalogInventoryStockItemList($session, array('27847')); // Products ID
print_r($result);

The above code has just been tested on my server which seems to be succesfull with this result:

Array ( [0] => stdClass Object ( [product_id] => 27847 [sku] => VKC450O [qty] => 0.0000 [is_in_stock] => 1 ) )

Let me know how you get on.