2015-05-07 13:16
浏览 73


I need rest api to create customer in magneto for that I followed this tutorial

I followed it step by step, But When I test the api on rest client it give me: {"messages":{"error":[{"code":404,"message":"Request does not match any route."}]}}

I do not have any idea where I am making mistake. Help me out here as I am very new to magento as well as for php.

The steps are:

1. Enabled Extension at (app/etc/module/Custom_Restapi.xml)


2. config.xml at (app/code/local/Custom/Restapi/etc/config.xml)

   <?xml version="1.0"?>

3. api2.xml at (app/code/local/Custom/Restapi/etc/api2.xml)

<?xml version="1.0"?>
            <restapi translate="title" module="Custom_Restapi">
                <title>Custom Rest API</title>
            <restapi translate="title" module="Custom_Restapi">
                <title>Testing My Rest API</title>
                <attributes  translate="" module="Custom_Restapi">
                    <firstname>First Name</firstname>
                    <lastname>Last Name</lastname>

4. Model Class Restapi.php at (app/code/local/Custom/Restapi/Model/Api2/Restapi.php)


class Custom_Restapi_Model_Api2_Restapi extends Mage_Api2_Model_Resource



5. V1.php at (app/code/local/Custom/Restapi/Model/Api2/Restapi/Rest/Admin/V1.php)

class Custom_Restapi_Model_Api2_Restapi_Rest_Admin_V1 extends Custom_Restapi_Model_Api2_Restapi

     * Create a customer
     * @return array

    public function _create() {

        $requestData = $this->getRequest()->getBodyParams();
        $firstName = $requestData['firstname'];
        $lastName = $requestData['lastname'];
        $email = $requestData['email'];
        $password = $requestData['password'];

        $customer = Mage::getModel("customer/customer");


       return  json_encode(array("testing","Success"));


And my url is like : baseurl/api/rest/customer

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • doumiang0597 2015-05-07 17:06

    I would put this in a comment since I feel this is not a fully complete answer, but I am not yet allowed to. A few things:

    1. Your global tag in config.xml is not closed.

    2. You cannot create records using a url that references entities, you have to use the collection route defined in the route_collection node in api2.xml. So you should be calling /api/rest/customer.

    3. There is no need to have a separate "create" route since the method is chosen by the http method (post/get/delete/etc) and the body content. I would recommend a route of "customer/:id" for the route_entity element. So also be sure that you are submitting an HTTP POST.

    I was not able to reproduce the exact error you posted, but I was able to get this working after correcting the above items.

    Also, be sure to give permission on this resource in the admin area and to clear your Web Services config caches.

    The specific exception you listed is thrown in Mage_Api2_Model_Router in the route method.

    I reworked this and created a repo on github with the working module: The module uses Guest access since I didn't have time to go through the whole oAuth deal, but if you simply update the guest node in api2.xml to admin and update your access in the admin area, it will work.

    解决 无用
    打赏 举报

相关推荐 更多相似问题