Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento API v2 PHP error

I'm trying to use SOAP with C#. Magento 1.4.2.

http://localhost/api/v2_soap/?wsdl

Here I can see the method catalogProductCreate

So I try to connect with:

$proxy = new SoapClient('http://localhost/api/v2_soap/?wsdl');

$sessionId = $proxy->login('xxx', 'xxxxxx'); // user with full access

$newProductData                     = new stdClass();
$newProductData->name               = 'Product Name';
$newProductData->description        = 'Description';
$newProductData->short_description  = 'Short Description';
$newProductData->websites           = array(138);
$newProductData->categories         = array(7,15);
$newProductData->status             = 1;
$newProductData->price              = 45;
$newProductData->tax_class_id       = 2;
$newProductData->weight             = 1;


$result = $proxy->catalogProductCreate(
    $sessionId,           // Soap Session
    'simple',           // Product Type
    4,                  // Attribute Set Id (Default)
    'product-sku',      // Product Sku
    $newProductData     // Product Data
);

But I receive this output:

Fatal error: Uncaught SoapFault exception: [4] Resource path is not callable.

like image 513
Ste Avatar asked Dec 15 '11 13:12

Ste


2 Answers

(details are Magento 1.6.x specific, but techniques, if not details, should be applicable to other versions)

I'm assuming, based on your code sample, that you're using PHP client code to test for the existence of a method, which you can then apply to a call from your C# application?

Assuming that's the case, it means you know PHP, so you'll want to debug this at the Magento soap server PHP level. The only class file that produces that fault is

app/code/core/Mage/Api/Model/Server/Handler/Abstract.php

Either add the following logging temporarily and directly to that file, or drop a copy of the class file in

app/code/local/Mage/Api/Model/Server/Handler/Abstract.php

for a codepool override.

Look in that class file for the following exception

throw new Mage_Api_Exception('resource_path_not_callable')

This is what causes the Magento soap server to response with that fault. There are four places this happens in that file. Add logging calls above each one.

Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
throw new Mage_Api_Exception('resource_path_not_callable');

This will let you know which fault is causing your problem, from which you can debug and log further. There are two places this can happen (four total in the file, one for a regular call, another for the multi-call).

In order of appearance, with possible causes in the comments.

//here magento is attempting to instantiate the "API Model" that will perform
//the work of your API call. Upon instantiation, it discovers that the model 
//doesn't inherit from Mage_Api_Model_Resource_Abstract, and bails.
//This is rare for a non-custom API call, but might be caused by a class rewrite
//gone amuck, or a very hacked system
try {
    $model = Mage::getModel($modelName);
    if ($model instanceof Mage_Api_Model_Resource_Abstract) {
        $model->setResourceConfig($resources->$resourceName);
    }
} catch (Exception $e) {
    Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
    throw new Mage_Api_Exception('resource_path_not_callable');
}


//Here Magento's been able to instantiate the $model, and is checking if the method is
//callable.  If not, it bails.  Again, for a standard, stock API call this shouldn't
//be happening, but could be the result of a rewrite gone wrong, or someone hacking an
//api class to make the method non accesible, or someone hacking the method mapping in api.xml
if (is_callable(array(&$model, $method))) {
    if (isset($methodInfo->arguments) && ((string)$methodInfo->arguments) == 'array') {
        return $model->$method((is_array($args) ? $args : array($args)));
    } elseif (!is_array($args)) {
        return $model->$method($args);
    } else {
        return call_user_func_array(array(&$model, $method), $args);
    }
} else {
    Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
    throw new Mage_Api_Exception('resource_path_not_callable');
}

Figure out why Magento is throwing the API error. It will often point to a type in your soap call, OR point you towards what's been hacked in your PHP system

like image 199
Alan Storm Avatar answered Sep 21 '22 04:09

Alan Storm


Making sure that you can she the wsdl resource is correct, but i also ran into that issue when i didnt have the user set up to the correct permissions under the role.

like image 38
Chris Horlick Avatar answered Sep 21 '22 04:09

Chris Horlick