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
Been there, done that 😛
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
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.
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 theSoapClient
instance, but pass SOAP API credentials to thelogin
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):
Just to play save, that you are didn’t got trapped by a typo: you pass
$GLOABLS["magento_api_password"]
as 2nd param to thelogin
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: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 variablesPHP_AUTH_USER
andPHP_AUTH_PW
.