4

I keep receiving this error in my exception log:

2016-10-14T09:20:43+00:00 ERR (3): 
exception 'Mage_Core_Exception' with message 'Invalid webservice adapter specified.' in /homepages/22/d123456/htdocs/mysite/app/Mage.php:595
Stack trace:
#0 /homepages/22/d123456/htdocs/mysite/app/code/core/Mage/Api/Model/Server.php(127): Mage::throwException('Invalid webserv...')
#1 /homepages/22/d123456/htdocs/mysite/api.php(84): Mage_Api_Model_Server->initialize(NULL)
#2 {main}

Also, this line is uncommented in my .htaccess:

###########################################
## rewrite API2 calls to api.php (by now it is REST only)

RewriteRule ^api/rest api.php?type=rest [QSA,L]
1

Your stack trace is showing that something odd is definitely afoot.

The key thing I'm seeing is that you are calling Mage_Api_Model_Server->initialize(NULL).

This function is defined like

public function initialize($adapterCode, $handler = null)
{
    /** @var $helper Mage_Api_Model_Config */
    $helper   = Mage::getSingleton('api/config');
    $adapters = $helper->getActiveAdapters();

    if (isset($adapters[$adapterCode])) {
        //Snipped for brevity, does adapter stuff
    } else {
        Mage::throwException(Mage::helper('api')->__('Invalid webservice adapter specified.'));
    }
    return $this;
}

If you pass in null, you are definitely not going to be selecting a valid adapter as $adapters[null] will not be a valid index key. I'm pretty sure null will be cast to the empty string in this instance, but there will not be any active adapters with the code of an empty string (or at least I hope not!)

The api.php file tries to call this initialise function like following (code edited for brevity).

//query parameter "type" is set by .htaccess rewrite rule
$apiAlias = Mage::app()->getRequest()->getParam('type');

/* @var $server Mage_Api_Model_Server */
$server = Mage::getSingleton('api/server');
$adapterCode = $server->getAdapterCodeByAlias($apiAlias);

// if no adapters found in aliases - find it by default, by code
if (null === $adapterCode) {
    $adapterCode = $apiAlias;
}
try {
    $server->initialize($adapterCode);

Based on your stack trace something is going wrong here and the final $adapterCode is ending up as null. The section of code which does the null === $adapterCode check will set the $adapterCode to be the value of your type parameter in the event that getAdapterCodeByAlias has returned null. This means that even if getAdapterCodeByAlias is returning null, it will ignore the value from that function so it can be disregarded from your issue.

The only way that I can see that $adapteCode will end up as null is if Mage::app()->getRequest()->getParam('type'); returns null. This is exactly how getParam is defined, it defaults to null if the parameter is missing.

public function getParam($key, $default = null)

All this boils down to the fact that you will likely be trying to access the api method without supplying a valid type parameter. This is an indication that your .htaccess file isn't configured properly. Try manually requesting with the type parameter, or get a systems admin to help figure out why the rewrite rules are not firing for you.

The valid types for me on a 1.14 magento instance are

echo implode(',', array_keys(Mage::getSingleton('api/config')->getActiveAdapters()))
#soap,soap_v2,soap_wsi,xmlrpc,default
  • Thank you for your answer Luke, it is appreciated. Since you mentioned my issue lies in .htaccess rewrites, I'm thinking maybe it could be my syntax for all of my rewrites were written for php 5.4 and I since I upgraded to php 5.6 it wasn't reading those rules. Thanks again for pointing me in the right direction. – jensusu Mar 3 '17 at 20:56
  • Installed a fresh .htaccess and still the same issue in my exception log. Any other suggestions would be greatly appreciated. – jensusu Mar 13 '17 at 14:29
  • Try hacking the api.php file so that $apiAlias = 'rest'; ? – Luke Rodgers Mar 13 '17 at 14:32
2

Thank u all for ur comments and response, it helped me to find a solution to my issue. I had on my htaccess file this line : RewriteRule ^api/rest api.php?type=rest [QSA,L] when I changed it to RewriteRule ^api api.php?type=rest [QSA,L] It worked for me.

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.