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?
Best Answer
As far as I understand you can only have a
route_entity
and aroute_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 ownapi2.xml
file you can have: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:
There is a good tutorial on http://devdocs.magento.com/guides/m1x/other/ht_extend_magento_rest_api.html