skip to Main Content

I am trying to access a Magento API, using SOAP. the code I have works fine normally, however the client wishes to password protect the Magento main folder. Doing so breaks access to the API and causes an error.

The documentation suggests this isnt a problem and you can just specify the username/password, however this does not work.

I am using PHP and IIS, with the password protection set up via Plesk 10. Does this use Basic HTTP authentication or something else?

My access code is:

$client = new SoapAuthClient($GLOBALS["magento_api_path"],array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) 
                    ); 
$session = $client->login($GLOBALS["magento_api_user"], $GLOABLS["magento_api_password"] ,
                    array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) ); 

The error I get is:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/" in C:Inetpubvhostsdomain.co.ukhttpdocsbackendindex.php:20 Stack trace: #0 C:Inetpubvhostsdomain.co.ukhttpdocsbackendindex.php(20): SoapClient->__call('login', Array) #1 C:Inetpubvhostsdomain.co.ukhttpdocsbackendindex.php(20): SoapClient->login('backenduser', 'backendwebuser', Array) #2 {main} thrown in C:Inetpubvhostsdomain.co.ukhttpdocsbackendindex.php on line 20

The line referred to is the $client->login command.

Any suggestions?

4

Answers


  1. Been there, done that 😛

        $client = new SoapClient("http://${http_user}:${http_pass}@subdomain.domain.com", array(
            'login' => $user,
            'password' => $pass,
        ));
    

    The problem is that the use of the http auth only happens during the requests and not while actually fetching the wsdl on the first request. To get around that, simply use the format i posted above: http://USERNAME:[email protected]/

    Cheers

    Login or Signup to reply.
  2. This problem is likely because internally Magento is requesting, via a local HTTP request, it’s own WSDL. As you’ve password protected the access, it’s not going to work. Modify the security to not require a password if the request is coming from localhost.

    Login or Signup to reply.
  3. I’ve faced a similiar problem long time ago.

    In my case, I didn’t immediately realize that I need to use .htaccess credentials while creating the SoapClient instance, but pass SOAP API credentials to the login method.

    I was passing the SOAP API credentials all over and got a similiar error like you do.

    Here’s what worked for me (1.3.x version, though. Still works for me as of today):

    $cProxy = new SoapClient(
        URL . 'index.php/api/soap/?wsdl',
        array(
            'login' => HTACCESS_USER,
            'password' => HTACCESS_PASS
        )
    );
    $rSessionId = $cProxy->login(
        SOAP_USER,
        SOAP_PASS
    );
    

    Just to play save, that you are didn’t got trapped by a typo: you pass $GLOABLS["magento_api_password"] as 2nd param to the login method, which should be $GLOBALS["magento_api_password"].

    Finally, you’re passing a 3rd argument to the login method which I believe is obsolete, since afaik it’s defined to have two params only:

    <message name="login">
        <part name="username" type="xsd:string" />
        <part name="apiKey" type="xsd:string" />
    </message>
    
    Login or Signup to reply.
  4. If you look at Mage_Api_Model_Server_Adapter_Soap::getWsdlUrl() you will see, that magento assumes that basic auth login and password are passed as environment variables PHP_AUTH_USER and PHP_AUTH_PW.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search