20

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.

user228395
  • 1,156
  • 1
  • 11
  • 25

8 Answers8

7

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

user228395
  • 1,156
  • 1
  • 11
  • 25
  • I had the same error and it was DNS related. My server was not live so I had my local host file modified to see the Magento site. Then when I called the login method via API, the API was doing its own DNS calls and being redirected to the public DNS IP which wasnt a Magento site, which then caused the error. Hope this helps! (This is in reference specifically to 1.7.0.2) – stitz Nov 16 '12 at 16:55
  • I had the same problem in Magento 1.9.0.1: The Magento SOAP API seems to do some internal HTTP-requests. Our (staging-) website was behind some `.htaccess`-rules that whitelisted only some specific IP addresses. Adding the servers' IP address to this list solved the problem for me. – Giel Berkers Feb 19 '15 at 09:23
  • I had this problem while testing Magento on a VM. I'd previously set the FQDN in /etc/hosts (for some reason) but the IP address on the interface had changed. If you can't ping the hostname from the host, but can from another machine, this could be the problem. – Kevin Sadler Feb 14 '17 at 11:27
  • @stitz could you pls explain briefly – Gem Mar 31 '18 at 12:26
  • @GielBerkers i have also same , could you pls explain briefly – Gem Mar 31 '18 at 12:26
3

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.

Francois Deschenes
  • 24,816
  • 4
  • 64
  • 61
  • I too was facing this problem in my loacalhost wamp server ,I had password protected my www directory using .htaccess file. Once password protection removed everythisng worked well. – Mukesh Mar 24 '14 at 10:18
1

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?

Doug McLean
  • 1,289
  • 12
  • 26
1

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.

Kelly L.
  • 31
  • 2
0

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

Jongosi
  • 2,305
  • 1
  • 28
  • 31
0

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

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

0

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

Jeff Thomas
  • 4,728
  • 11
  • 38
  • 57