Magento API v2 PHP error
Asked Answered
F

4

5

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.

Ferd answered 15/12, 2011 at 13:38 Comment(5)
Which part of the error don't you understand exactly? Can you elaborate?Padgett
localhost/api/v2_soap/?wsdl open it in your browser see if there is such method as catalogProductCreateIguanodon
I know this mean that i can't find that method..but i can see it in the xml... How can I do for solve this?Ferd
YES I CAN SEE catalogProductCreate METHOD....Ferd
How is this related to C#?Smasher
R
17

(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

Reata answered 15/12, 2011 at 21:26 Comment(6)
2011-12-16T10:39:12+00:00 DEBUG (7): Line 295 in file /usr/www/app/code/core/Mage/Api/Model/Server/Handler/Abstract.phpFerd
Log get_class($model) and $method. Perhaps you don't have such method in this model.Iguanodon
I have the same problem here (second if). I logged the Model and my method there is in method's list of Model, but apparently is not callable. Permission Rules able for ALL.Tarantass
I did it in my test server and it's work. But in my prod server I got the resource_path_not_callable exception.Tarantass
@DenisSpalenza Then add some debugging code to see what's in $model and $method, and figure out why PHP thinks they're not callable.Reata
@AlanStorm Thank you for your attention. I got my error, one caracter missing, rsrs.Tarantass
C
1

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.

Chartist answered 15/12, 2011 at 19:1 Comment(0)
A
1

Try to create a webservice user with role and assigned them to a role that has access to ‘ALL’. option in role resources menu in role information.

Avion answered 1/4, 2014 at 7:0 Comment(0)
M
0

Put this file into root folder of magento/project so that you can access all the method of magento.

Enjoy the idea...

Missy answered 21/1, 2014 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.