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?

5 Answers 5


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.


$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

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.

  • Thats the same code as i am already using right? Magento version
    – eleven11
    Sep 18, 2013 at 22:44
  • Yes, without using lots of variables, and keeping it simpler, could you provide url link? Also, are you in WS-I COMPLIANCE mode or not? Sep 18, 2013 at 22:45
  • WS-I COMPLIANCE - No.. But this is an issue with logging in, not anything to do with requests or XML formats
    – eleven11
    Sep 18, 2013 at 23:57
  • I have editted my answer Sep 19, 2013 at 9:03
  • 3
    ok i fixed it... In this table api_role.. There was an entry for a user (role_type = U). For each one of these users, there needs to be a role_id (role_type = G) that has an id of the users parent_id.. So i deleted the user with no referenced parent and it fixed the issue
    – eleven11
    Sep 19, 2013 at 14:17
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient(

$session = $client->login('imran', '654321imran');

$result = $client->catalogProductList($session,'sku');


  • 1
    It would be much better if you provide some explanation as well with the code.
    – Prateek
    Oct 20, 2015 at 13:00

One idea: load the WSDL-config with cUrl like this example and try it again:

// ==========================

    $objCURL = curl_init([API-URL]); // Set API-URL
    curl_setopt($objCURL,CURLOPT_RETURNTRANSFER, true);
    $strWSDLFile = curl_exec($objCURL);


// =================

    try {
        $soap = new SoapClient('wsdl_temp.xml');
        $soapSession = $soap->login([API-User], [API-Key]);
    } catch(Exception $e) {

This solves all MY problems with the API. :-)


The solution is to
1. create a new SOAP/XML-RPX Roles, say "Test"
2. in Role Resources just select "All" for Resource Access (just for testing)
3. Edit the user and assign the Role to "Test"


SoapFault: Forbidden in C:\Program Files (x86)\Ampps\www\soap\class_01.php on line 128

In fact, if I use Soap in http://localhost/.... it works, the connection is successful, but if I use same methods with in external IP and a port (like returns this error:

Fatal error: Uncaught SoapFault exception: [HTTP] Forbidden in C:\Program Files (x86)\Ampps\www\soap\class_01.php on line 128

SoapFault: Forbidden in C:\Program Files (x86)\Ampps\www\soap\class_01.php on line 128

The firewall is disabled, the ports are open. I do not know what to look for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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