Magento – Rest Api. How to control attribute in api2.xml with attribute rules when attribute contains the attributes array of object in other table

apimagento-1.9

My JSON string like this:

{
  "id": "74",
  "created_at": "2015-07-22 09:36:57",
  "created_by": "1",
  "updated_at": "2015-07-22 09:36:57",
  "updated_by": "1",
  "store": {
    "group_id": "1",
    "website_id": "1",
    "name": "Main Website Store",
    "root_category_id": "2",
    "default_store_id": "1",
    "group": [
      {
        "id": "4",
        "name": "group 4 - store web 2",
        "description": null,
        "level": "1",
        "product": [
          {
            "id": "1",
            "created_at": "2015-07-20 07:54:07",
            "created_by": "1",
            "updated_at": "2015-07-20 07:54:07",
            "updated_by": "1"
          },
      }
    ]
  }
}

it's mean in House have one "store", in "store" have many "group" and in "group" have many "product".
I tried adding the attributes as group, product to file api2.xml to manage in the Edit attribute rules but it does not work when I unchecked.
"group", "product" are on the table different database.

My api2.xml:

<config>
    <api2>
        <resource_groups>
            <house translate="title" module="Hihi_House">
                <title>House API Call</title>
                <sort_order>20</sort_order>
            </house>
        </resource_groups>
        <resources>
            <house translate="title" module="Hihi_House">
                <group>house</group>
                <model>hihi_house/api2_house</model>
                <title>House API</title>
                <sort_order>10</sort_order>
                <privileges>
                    <customer>
                        <retrieve>1</retrieve>
                    </customer>
                </privileges>
                <attributes>
                    <id>Id</id>
                    <name>Name</name>
                    <store>Store</store>
                    <group>Group</group>
                    <product>Product</product>
                    <created_at>Created At</created_at>
                    <created_by>Created By</created_by>
                    <updated_at>Updated At</updated_at>
                    <updated_by>Updated By</updated_by>
                </attributes>
                <routes>
                    <route_entity>
                        <route>/house</route>
                        <action_type>entity</action_type>
                    </route_entity>
                    <route_collection>
                        <route>/house/list</route>
                        <action_type>collection</action_type>
                    </route_collection>
                </routes>
                <versions>1</versions>
            </house>
        </resources>
    </api2>
</config>

Thanks!

Best Answer

In api2.xml the attributes you define are top-level attributes. You cannot use them to filter nested data arrays, at least not using unmodified core code.

The only attributes you have defined the will do anything are:

  • id
  • created_at
  • created_by
  • updated_at
  • updated_by
  • store
Related Topic