2

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

3

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.

9
  • Thats the same code as i am already using right? Magento version 1.7.0.2
    – eleven11
    Commented 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? Commented 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
    Commented Sep 18, 2013 at 23:57
  • I have editted my answer Commented 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
    Commented Sep 19, 2013 at 14:17
0
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient(
    'http://127.0.0.1/magento/api/v2_soap/?wsdl'
);

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

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

print_r($result->product_id);

$client->endSession($session);
1
  • 1
    It would be much better if you provide some explanation as well with the code.
    – Prateek
    Commented Oct 20, 2015 at 13:00
0

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

// GET SOAP-WSDL AS TEMP-FILE
// ==========================

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

    file_put_contents('wsdl_temp.xml',$strWSDLFile);

// INIT SOAP-SESSION
// =================

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

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

0

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"

0

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 http://82.82.10.10:8080/...) 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.