7

When fetching the V2 WSDL via this URL:

www.example.com/shop/api/v2_soap?wsdl=1

It is defining the wrong URL for requests:

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

As you can see above, it is returning this URL:

www.example.com/shop/index.php/?type=v2_soap

Although it should be:

www.example.com/shop/index.php/api/v2_soap/index/

I've hunted down through a lot of the Magento core code and I believe that value get set in /app/code/core/Mage/Api/Model/Wsdl/Config/Base.php around line 53:

    // set up default WSDL template variables
    $this->_wsdlVariables = new Varien_Object(
        array(
            'name' => 'Magento',
            'url'  => htmlspecialchars(Mage::getUrl('*/*/*', array('_query' => $queryParams)))
        )
    );

This part is what appears to be failing:

Mage::getUrl('*/*/*' ...

If I change that to:

Mage::getUrl('api/v2_soap/index' ...

the correct URL is returned.

This question appears to be describing the exact same problem, but there was never an answer for it:

Thanks in advance for any help!

UPDATE

Although I've yet to find a permanent solution to this issue, I have found a temporary solution after searching around a bit. Essentially, I extend the SoapClient class and override the __doRequest method as a means of intercepting requests and tweaking the location URL before the request is sent:

class SoapClientLocation extends \SoapClient
{
    public function __doRequest( $req, $location, $action, $version = SOAP_1_1, $one_way = NULL )
    {
        $location = str_replace( '?type=v2_soap', 'api/v2_soap/index/', $location, $one_way );
        return parent::__doRequest( $req, $location, $action, $version );
    }
}

 $this->client = new SoapClientLocation( $this->config['api']['url'] );
  • System -> configuration -> Web -> Url Options -> Auto-redirect to Base URL. Set that to 'No' – B00MER Jul 17 '15 at 5:12
  • I've tried that a few different times and it appears to have no effect. – forgueam Jul 17 '15 at 12:41
2

It can be two issues:

  1. Use www.example.com/shop/index.php/api/v2_soap/?wsdl instead of www.example.com/shop/api/v2_soap?wsdl=1 (note the added index.php)
  2. Make sure that you disabled error_reporting/display_errors in your index.php.

Long note on the last point: The SoapClient isn't a browser and therefore doesn't send cookies, Magento in turn likes cookies and therefore Magento trows a Notice (when error_reporting is enabled), the notice makes your XML invalid/doesn't even make it load. (SOAP-ERROR: Parsing WSDL: Couldn't find <definitions>)

  • I tried adding index.php/ to the URL and it didn't appear to help. I'm going to try looking into the error reporting. Thanks for the tip! – forgueam Jul 29 '15 at 12:56
0

The issue is that

Mage_Api_Controller_Action::preDispatch()

Sets the current store to 'admin' (more information in Alan's blog post http://alanstorm.com/magento_api_adapater_xml_rpc)

If you have 'Auto-redirect to Base URL' set, then the API won't be accessible.

My solution was listen to

controller_front_init_before

And zero out that config node if the URI contains 'api'. I.e.

public function controllerFrontInitBefore($observer) {
    if (stristr(Mage::app()->getRequest()->getRequestUri(), 'api')) {
        Mage::getConfig()->setNode('stores/' . Mage::app()->getStore()->getCode() . '/web/url/redirect_to_base', 0);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.