1

Running Magento V1.9 with Rest API

I can extract data using the REST api, but I need to exctract a list of categories and might even have the ability to add a new category through the API.

I have tried creating an module inside local and community folders, but I have this response returned.

exception 'Mage_Api2_Exception' with message 'Request does not match any route.'

QUESTION: Could it be caused by an error in my folder structure?

Inside api2.xml i think, theres must be a match between the route section and my call the API.

CALL: magentohosturl/api/rest/restapi/categories

Route section from api2.xml

 <routes>                
      <route_entity>
          <route>/restapi/categories/:cat_id</route>
          <action_type>entity</action_type>
      </route_entity>
      <route_collection>
           <route>/restapi/categories</route>
           <action_type>collection</action_type>
      </route_collection>
  </routes>

Question: Is there something I might have overlooked that effects the route?

Full api2.xml file

<?xml version="1.0"?>
<config>
<api2>
    <resource_groups>
        <catalog translate="title" module="RestApi_Categories">
            <title>Category Rest API extension</title>
            <sort_order>10</sort_order>       
        </catalog>
    </resource_groups>
    <resources>
        <categories translate="title" module="RestApi_Categories">
            <group>category</group>
            <model>categories/api2_categories</model>
            <title>Categories retrieval</title>
            <sort_order>10</sort_order>
            <privileges>
                <admin>
                    <retrieve>1</retrieve>
              <!--  <create>1</create>
                    <update>1</update>
                    <delete>1</delete>  --> 
                </admin>               
            </privileges>
            <attributes translate="entity_id name parent_id child_id is_active level position" module="RestApi_Categories">
                <entity_id>Category ID</entity_id>
                <name>Name</name>
                <parent_id>Category Parent ID</parent_id>
                <child_id>Category Child List</child_id>
                <is_active>Active</is_active>
                <level>Level</level>
                <position>Position</position>
            </attributes>
            <routes>                
                <route_entity>
                        <route>/restapi/categories/:cat_id</route>
                        <action_type>entity</action_type>
                    </route_entity>
                <route_collection>
                        <route>/restapi/categories</route>
                        <action_type>collection</action_type>
                </route_collection>
            </routes>           
            <versions>1</versions>
        </categories>
    </resources>
</api2>
</config>

QUESTION: How do I check wether the file is loaded or not?

Filepath: \app\code\community\RestApi\Categories\etc

Followed this guide to enable developer debug mode. http://www.blog.magepsycho.com/configuring-magento-for-development-debug-mode/

Routes from Api2 files is loaded here in function getRoutes($apiType): \app\code\core\Mage\Api2\Model\Config.php

Exception log contains an error message if my api2.xml is manpulated to fail.

Errors message is also present in returned answer from Magento API, so I can confirm my api2.xml is loaded and validates, but the contained routes inside, must be wrong.

Since I've found the routes function I should be able to debug what happens.

3
  • At a first glance, the routes look ok to me. are you sure your api2.xml is loaded? Or maybe it's not valid.
    – Marius
    Aug 21, 2014 at 8:18
  • 1
    Here is how you can check if your file is loaded. Turn on the developer mode and make your xml not valid (remove a closing tag for example). If your file is loaded you should see an error on the screen.
    – Marius
    Aug 21, 2014 at 10:59
  • Just come across a similar problem myself - in my case, looks like api2.xml is not loaded. Why would that be? I've installed my module on multiple sites before and this is the first time I've had this problem. I'm guessing it's to do with the fact this is the first 1.9.2.4 site I've installed it on. Perhaps I need to raise a new question... May 9, 2016 at 10:14

1 Answer 1

-1

Route must look like this rest/api/categories and not just /categories

Now it's resources that fails, so I will provide a full copy, if I get there :)

Thanks Marius for input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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