Extend Magento REST API in a custom module

I want to use Magento Rest-Api to add user data to a Magento table. I added one table to the Magento database and created a module with the Rest API for this using the following link

http://web.archive.org/web/20130512072025/http://magepim.com/news/Extending-the-Magento-REST-API-part-1_13

Now I want to add data to the Magento table using the Rest API ...

what i need to change in api.xml/ api2.xmlor in the V1.phpfile.

Please help me. I tried a lot of codes using the link to the api2.xml file. but no luck.

when i run the following url

http://magento-host/api/rest/magepim/products/count

it will execute the V1.phpfile function _retrieve(), but how to call the function _create()usingPHP RestApi oauth

+4
source share
1 answer

Magento \ application \ code \ kernel \ Mage \ API2 \ Model \ Resource.php only the collection action type for the create method is allowed. therefore, it was changed in the api2.xml file and set the necessary fields in the attribute tag

Magento \ application \ code \ community \ MagePim \ Extapi \ etc. \ api2.xml

<?xml version="1.0"?>
<config>
    <api2>
        <resource_groups>
            <extapi translate="title" module="api2">
                <title>Custom API calls</title>
                <children>
                    <extapi translate="title" module="api2">
                        <title>My Api</title>
                    </extapi>
                </children>
            </extapi>
        </resource_groups>
        <resources>
            <extapi translate="title" module="api2">
                <group>extapi</group>
                <model>extapi/api2</model>
                <working_model>extapi/api2</working_model>
                <title>Custom Api</title>
                <privileges>
                    <admin>
                        <create>1</create>
                        <retrieve>1</retrieve>
                        <update>1</update>
                        <delete>1</delete>
                    </admin>
                </privileges>
                <attributes>
                    <owner_id>Owner ID</owner_id>
                    <identityid>Identity ID</identityid>
                    <social_id>Social ID</social_id>
                    <status>Status</status>
                    <text>Text</text>
                    <request_timestamp>Request Time</request_timestamp>
                    <status_timestamp>Status Time</status_timestamp>
                </attributes>
                <routes>
                    <!-- Call For V1.php _retrieve() -->
                    <route_entity>
                        <route>/scheduler</route>
                        <action_type>entity</action_type>
                    </route_entity>
                    <!-- Call For V1.php _create() -->
                    <route_collection>
                        <route>/scheduler/create</route>
                        <action_type>collection</action_type>
                    </route_collection>
                </routes>
                <versions>1</versions>
            </extapi>
        </resources>
    </api2>
</config>

Magento \ application \ code \ community \ MagePim \ Extapi \ Model \ API2 \ Rest \ Admin \ V1.php

/**
 * Override for Magento REST API
 */
class Magepim_Extapi_Model_Api2_Rest_Admin_V1 extends Mage_Api2_Model_Resource {

    protected function _retrieve(){
        return json_encode($shedulerData);
    }
    protected function _create($shedulerData){
        return json_encode($shedulerData);
    }
    protected function _retrieveCollection(){
        return json_encode(array('method'=>'_retrieveCollection'));
    }
....................
}
+3
source

Source: https://habr.com/ru/post/1530413/


All Articles