Magento – Magento soap api login failed using PHP

apimagento-1soap

I am working with magento soap api and it's works fine in my local machine and development server but when i moved my code to production server i found the following error:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.mydomain.com/magento/index.php/api/soap/index/?wsdl=1' : failed to load external entity "http://www.mydomain.com/magento/index.php/api/soap/index/?wsdl=1" Stack trace: #0 [internal function]: SoapClient->__call('login', Array) #1

I have also check the SOAP setting on server everything is OK but still this error comes.

Best Answer

Do you have WS-I compliance turned on or off? Calls are somewhat stricter when WS-I Compliance mode is enabled.

Also it is worth checking if WSDL cache is enabled or not. Generally speaking wsdl caches on linux/unix based systems store a cached version of the WSDL here: -

cd /tmp/

You can use the following command to clear them out

sudo rm -rf /tmp/wsdl*

I also assume you are intending to use SOAP V1 not V2 if so you should use the following URL: -

http://www.domain.com/index.php/api/v2_soap?wsdl

If this does not help then it would be best if you could provide more detail here. The SoapClient in php allows you to pass params in the constructor, so if you pass something like the following, you can see some more information.

try {
$client = new SoapClient('http://www.domain.com/index.php/api/v2_soap/?wsdl', array('trace' => 1, 'connection_timeout' => 120));

$session = $client->login(array(
        'username' => 'user',
        'apiKey' => 'pass')
);

}
catch (Exception $e) {
    var_dump($e);
}
header('Content-type: application/xml');
echo $client->__getLastResponse();
// or echo $client->__getLastRequest();

If you could echo out 1 then the other and copy back here so can have a look may be able to help you further. For more info on SoapClient check the php website.

Related Topic