0

My route section in api2.xml

 <routes>
                <route_collection>
                    <route>/mymodule/user</route>
                    <action_type>collection</action_type>
                </route_collection>  
                <route_create>
                    <route>/mymodule/user/create</route>
                    <action_type>create</action_type>
                </route_create>     
                <route_update>
                    <route>/mymodule/user/update/:id</route>
                    <action_type>update</action_type>
                </route_update>               
            </routes>

My model methods: mymodule/Model/Api2/User/Rest/Guest/V1.php

I extend Mage_Api2_Model_Resource

public function _retrieve() {
    return json_encode(array(0=>'retrieve Function Call done')); 
}

//Collection
public function _retrieveCollection() {
      //Some codes 
   return json_encode(array(0=>'retrieveCollection Function Call done')); 
}

//Create
public function _retrieveCreate() {
     //Some codes
     return json_encode(array(0=>'retrieveCreate Function Call done')); 
}

//Update
public function _retrieveUpdate) {
     //Some codes
     return json_encode(array(0=>'retrieveUpdate Function Call done'));
}

I get an error message on API call magento-host/api/rest/mymodule/user/create "code": 405," message": "Resource method not implemented yet."

How can I resolve this?

2 Answers 2

1

As far as I understand you can only have a route_entity and a route_collection and with those you can have a GET, PUT, POST and DELETE (have a look at http://www.restapitutorial.com/lessons/httpmethods.html) and they will match functions called _retrieve, _update, _create and _delete. To implement your own REST API methods have a good look at e.g. api2.xml in the customer module. So for instance in your own api2.xml file you can have:

<privileges>
   <admin>
     <create>1<create>
     <update>1</update>
     <retrieve>1</retrieve>
   </admin>
   ....
   <routes>
     <route>/myextension/myproduct/:product_id</route>
        <action_type>collection</action_type>
     </route>

Note that I use admin here because a Guest can use only GET. My admin role can now POST (create) and PUT (update) and GET (retrieve).

My code would then look like this:

class Mymodule_Myextension_Model_Api2_Myproduct_Rest_Admin_v1 extends Mymodule_Myextension_Model_Api2_Myproduct
{
protected function _update($productData)
{ ... }
protected function _create($productData)
{ ... }
protected function _retrieve($productData)
{ ... }

There is a good tutorial on http://devdocs.magento.com/guides/m1x/other/ht_extend_magento_rest_api.html

0

set value collection for CREATE action type and entity for UPDATE action type

Your Answer

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

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