user228395
user228395

Reputation: 1176

Unable to connect to Magento SOAP API v2 due to "failed to load external entity"

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.

Upvotes: 20

Views: 30457

Answers (8)

Gregory Rios
Gregory Rios

Reputation: 11

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');

Upvotes: 0

Devendra Gupta
Devendra Gupta

Reputation: 101

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.

Upvotes: 0

Jongosi
Jongosi

Reputation: 2355

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

Upvotes: 0

Doug McLean
Doug McLean

Reputation: 1309

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?

Upvotes: 1

Kelly L.
Kelly L.

Reputation: 31

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.

Upvotes: 1

Francois Deschenes
Francois Deschenes

Reputation: 24969

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.

Upvotes: 3

Jeff Thomas
Jeff Thomas

Reputation: 4816

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

Upvotes: 0

user228395
user228395

Reputation: 1176

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

Upvotes: 7

Related Questions