Fetching menu tree using JSON-RPC api based on user groups

Hello ,

i was able to fetch the menu tree based on the menu id send on the params in below json

  {
     "method": "model.ir.ui.menu.read",
      "params": [
        [
          54,
          131
        ],
        [
          "active",
          "childs",
          "name",
          "parent",
          "parent.rec_name",
          "rec_name",
          "_timestamp"
        ],
        {
          
          
          "groups": [
            10
          ]
        }
      ]
    }

but i was looking for some thing that would fetch the menu tree base on user group assign to user

By default, the search call on ir.ui.menu filters the menu for which the user has no access.

Thanks a lot @ced greatly appreciated i was able to get the data without sending menu id’s in params with the following JSON

{
  "id": 12,
  "method": "model.ir.ui.menu.search",
  "params": [
    [
      [
        "parent",
        "=",
        null
      ]
    ],
    {
      "client": "c25196fd-d471-4c42-8a80-78fa5112d611",
      "employee": null,
      "company": null,
      "language": "en",
      "language_direction": "ltr"
      
    }
  ]
}

is it possible to get the data of the child as well parent in a single request or is there some kind of json serializer the would format the data as in required json format both with parent and child together

You can use search_read with for example as fields: ['name', 'childs.name']. But this gives you only one level. Of course you can ask more levels with ['name', 'childs.name', 'childs.childs.name']. But as menu can have an infinite depth level, it is probably better to request each level/branch on demand.

Thanks a lot cedric for the reply i tried hittiing the below json seems it return 500 internal server error

   {
  
  "method": "model.ir.ui.menu.search_read",
  "params": [
    [
      54,
      131
    ],
    [
      "active",
      "childs",
      "name",
      "parent",
      "parent.rec_name",
       "childs.name",
      "rec_name",
      "_timestamp"
    ],
    {
      
      
      "groups": [
        10
      ]
    }
  ]
}

any clue where it did go wrong

Edited:
Was able to get the response but cant get the data of the childs with the following json

{"id":12,"method":"model.ir.ui.menu.search_read","params":[[[ ["childs" ,"childs.name"]]],0,1000,null,{"client":"05ec1b7b-dea1-441a-8e3a-336447a5bf7c","employee":null,"company":null,"language":"en","language_direction":"ltr","groups":[10]}]}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.