20
votes

I am unable to connect to the Magento SOAP API v2 using PHP. The error that occurs is:

PHP Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.example.com/index.php/api/v2_soap/index/wsdl/1/' : failed to load external entity "http://www.example.com/index.php/api/v2_soap/index/wsdl/1/"

As it seems, the WSDL is being loaded, but the external SOAP file which it includes not.


PHP connection code:

$client = new SoapClient('http://www.example.com/api/v2_soap?wsdl=1');
$session = $client->login('username', 'password');

Snip from v2_soap?wsdl=1 file:

<service name="MagentoService">
    <port name="Mage_Api_Model_Server_V2_HandlerPort" binding="typens:Mage_Api_Model_Server_V2_HandlerBinding">
        <soap:address location="http://www.example.com/index.php/api/v2_soap/index/"/>
    </port>
</service>

Magento version is 1.5.1.0.

8
Have you tried to open mydomain.com/index.php/api/v2_soap/index/wsdl/1 in your browser?Dmytro Zavalkin
Yes, which seemingly works fine.user228395
Is this running locally or on a valid domain?B00MER
On a valid, existing domain name.user228395
I suppose there is a problem with DNS lookup, if you are performing request from the same server or network where the server is placed it may not see itself. It is a problem of server configuration.Ivan Chepurnyi

8 Answers

7
votes

This problem is caused by the server not being able to access the file from the local machine. So the possible cause could've been the DNS server or /etc/hosts, but it was actually a .htaccess file blocking any hosts except from our development computers. This resulted in a 403 Forbidden error, which resulted in the SOAP error and so on..

3
votes

I've experience a similar problem recently on a public-facing development server. The problem was the I was using a .htaccess file to prevent unauthorized use of the site and I forgot to add the server's own IP addresses to the list. Once I added it, it solved the problem.

Make sure that you don't have any rules forbidding access to your content.

1
votes

Make sure that php.ini enables SSL. add this to your file: extension=php_openssl.dll

I had this problem and that was what fixed it.

1
votes

tl;dr: Check the API username and API key.

Unfortunately, SOAP is giving you a generic error message which could mean a number of things.

One possible candidate is a routing problem, i.e. the server tries to send itself a request but it fails, perhaps because it's using its own public IP address to do so and this doesn't work, because of reasons.

To see if this is the case on your server, log into it (e.g. with SSH) and try pinging the hostname. If the ping works, routing is almost certainly not the problem. If the ping fails, try adding the hostname into your hosts file (typically /etc/hosts) with the IP address 127.0.0.1 (or ::1 if you're into IPv6).

But another possible reason, and one I experienced myself recently, is simply that you've not provided the correct API username and API key. SOAP - at least, the way Magento implements it - doesn't seem to have an "access denied" or "login failed" response. Because of this, it's hopeless testing API functions in a browser. http://www.example.com/api/v2_soap?wsdl=1 works in a browser as the WSDL isn't password-protected. But the endpoint itself is, so http://www.example.com/index.php/api/v2_soap/index/* will fail.

One other possiblity, did you change your store's domain name recently and not flush the "webservices configuration files" caches?

0
votes

Are you on a shared hosting account? It is possible that your provider is blocking access to the port.

0
votes

This error could also be related to the SSL ciphers that your server is set to use. The current recommended suite of ciphers (note that these will need updating in time) is ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS.

Obviously you should follow the recommended procedure to update your relevant OS and it's SSL ciphers.


If your server is running Plesk Control Panel, versions 11 onwards, there is a particular fix:

  1. Upgrade the 'openssl' package to version 1.0 and higher.

  2. Enable nginx:

    /usr/local/psa/admin/bin/nginxmng --enable

  3. Create a custom domain template for nginx:

    mkdir -p /usr/local/psa/admin/conf/templates/custom/domain/

    cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain

  4. Edit the file you just copied:

    vi /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php

    Look for the line <?php if ($OPT['ssl']): ?> and insert the following immediately after:

    ssl_protocols TLSv1.1 TLSv1.2; ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;

    Save the file.

  5. Reconfigure the vhosts.

    /usr/local/psa/admin/bin/httpdmng --reconfigure-all


Credit: This fix is documented by Odin directly: http://kb.odin.com/en/120083

0
votes

Go To Admin Dash board > system > configuration > web > Search engine Optimization > Use web Server rewrite "Set it to No"

For me it was the Fix.

0
votes

I wanted to contribute the following, depending on the server and the Magento configuration, this simple solution can work. is to add the index.php to the URL

$client = new SoapClient('https://www.TU-domain.com/index.php/api/v2_soap/?wsdl');