Problem connecting to SOAP API in password protected directory

I am trying to access the Magento API using SOAP. The code works fine for me, but the client wants to password protect the main Magento folder. This violates the access to the API and causes an error.

The documentation assumes this is not a problem, and you can simply provide a username / password, however this will not work.

I use PHP and IIS, with password protection configured through Plesk 10. Does it use plain HTTP authentication or something else?

My access code:

$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 am getting 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 specified line is the command $ client-> login.

Any suggestions?

+4
source share
4 answers

This problem is likely because internally Magento requests its own WSDL through a local HTTP request. Since you have a password protected by access, it will not work. Change the security to not require a password if the request comes from localhost.

+2
source

I have long encountered a similar problem.

In my case, I did not immediately understand that I needed to use the .htaccess credentials when creating the SoapClient instance, but pass the SOAP API credentials for the login method.

I was passing SOAP API credentials around the world and getting a similar error like you.

Here's what worked for me (version 1.3.x, although it works for me 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, you don't fall into the trap of typos: you pass $GLOABLS["magento_api_password"] as the second parameter to the login method, which should be $GLOBALS["magento_api_password"] .

Finally, you pass the third argument to the login method, which, it seems to me, is deprecated since afaik, by its definition, has only two parameters:

 <message name="login"> <part name="username" type="xsd:string" /> <part name="apiKey" type="xsd:string" /> </message> 
+8
source

There, it is made that: P

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

The problem is that using HTTP authentication only happens during requests, not when receiving wsdl on the first request. To get around this, simply use the format above: http: // USERNAME: PASSWORD@server.com /

Greetings

+4
source

If you look at Mage_Api_Model_Server_Adapter_Soap::getWsdlUrl() , you will see that magento assumes that the base auth login and password are passed as environment variables PHP_AUTH_USER and PHP_AUTH_PW .

0
source

All Articles