Search code examples
phpmagentosoapiis-7.5magento-soap-api

Problem connecting to a SOAP API in password protected directory


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:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php:20 Stack trace: #0 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->__call('login', Array) #1 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->login('backenduser', 'backendwebuser', Array) #2 {main} thrown in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php on line 20

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

Any suggestions?


Solution

  • 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.