简体   繁体   English

在自定义模块中扩展Magento REST API

[英]Extend Magento REST API in custom module

I want to use Magento Rest-Api to add custom data into Magento table. 我想使用Magento Rest-Api将自定义数据添加到Magento表中。 I have added one table into Magento db and created module with Rest API for that using following link 我已经在Magento数据库中添加了一个表,并使用以下链接创建了具有Rest API的模块

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

Now I want to add data into Magento table using Rest API... 现在我想使用Rest API将数据添加到Magento表中...

what I need to changed in api.xml / api2.xml or in V1.php file. 我需要在api.xml / api2.xmlV1.php文件中进行更改。

Kindly help me I have tried many codes using reference of product api2.xml file. 请帮助我,我使用产品api2.xml文件的参考尝试了很多代码。 but no luck. 但没有运气。

when I run following URL 当我运行以下URL

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

it will executed V1.php file's _retrieve() function but how to call _create() function using PHP RestApi oauth 它将执行V1.php文件的_retrieve()函数,但如何使用PHP RestApi oauth调用_create()函数

magento\\app\\code\\core\\Mage\\Api2\\Model\\Resource.php is only allowed collection action type for create method.. so changed in api2.xml file and setup required fields in attribute tag magento \\ app \\ code \\ core \\ Mage \\ Api2 \\ Model \\ Resource.php只允许创建方法的集合操作类型..所以在api2.xml文件中更改并在属性标记中设置必填字段

magento\\app\\code\\community\\MagePim\\Extapi\\etc\\api2.xml Magento的\\ APP \\代码\\社区\\ MagePim \\ Extapi \\等\\ 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\\app\\code\\community\\MagePim\\Extapi\\Model\\Api2\\Rest\\Admin\\V1.php Magento的\\ APP \\代码\\社区\\ MagePim \\ Extapi \\型号\\ API2 \\休息\\管理\\ V1.php

/**
 * Override for Magento's 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'));
    }
....................
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM