2

I am searching products using magento api. created one input box and search button where user will enter the product name and submit the keyword. It will search the products using the key word and name attribute. But it is showing the error:

Call to a member function getRole() on a non-object

I have checked user which i created, user role and user role assigned to user and role resources but still issue the same.. here is my code

  <form action="" method="get"> <input type="text" name="searchWord" /> <input type="submit" value="search" name="search" /> </form> <?php if(isset($_GET['search'])){

    // creating soap client $client = new SoapClient('http://localhost/magento/index.php/api/soap/?wsdl');

    // creating session for login 

    $sessionId = $client->login('myusername','apiKey');

    $searchKeyWord = $_GET['searchWord'];

    $filters = array(
                    'name' => array('like'=>"%$searchKeyWord%")
                     ); 
var_dump($filters);
 try{ $result = $client->call($sessionId, 'catalog_product.list', array($filters)); } catch(Exception $e){ echo $e->getMessage();
        return;

    }

I have tried other method too.. like

$result = $client->call($sessionId, 'catalog_product.info', '1') and its working fine but catalog_product.list is not working.. Any idea

Thanks in advance :)

  • Did you create an API User and assigned a role to it? – FlorinelChis Nov 28 '13 at 14:38
  • @FlorinelChis .. thanks for your comment ...Yes I have created as well and even i have given full access to the user bt issue is the same... – MagentoBoy Nov 29 '13 at 4:59
1

I think the cause is, that you never set the variable $client in this code snippet. It´s commented out. I guess you have initialized the variable somewhere else before this snippet in your code. That´s why it works sometimes.

You should change the line

 // creating soap client $client = new SoapClient('http://localhost/magento/index.php/api/soap/?wsdl');

to the following (two lines!!!):

 // creating soap client
$client = new SoapClient('http://localhost/magento/index.php/api/soap/?wsdl');
  • @alpham8.. I have done that... while pasting code i just missed code. However, it is working on other installation. I dont know what is the issue... when do we get this error?? even I searched in google but issue is the same – MagentoBoy Oct 17 '13 at 9:45
  • is there anyone... :( – MagentoBoy Oct 18 '13 at 7:03
  • 1
    yes :-) If it works on other Magento installations with the same code, then it isn´t a code problem. Look at your settings, modules, etc. if there something went wrong. – alpham8 Oct 18 '13 at 9:44
0

I had the same issue and after a long debugging session, I found out that the error is caused by the extension MagentoHackathon_AdvancedAcl. I opened an issue and created a pull request, which fixes this issue.

The problem is that they execute the following code:

Mage::getSingleton('admin/session')->getUser()->getRole();

But in the case of a SOAP API call, there is no user in the admin session.

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.