"Fields", "nestedFields" and "Restrict Fields" do not filter out the data in the API response body
written-by
Rishabh Agrawal
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
legacy-article
learn-legacy-article-disclaimer-text
Issue
- While using the Navigation Menu Headless API (`/o/headless-delivery/v1.0/navigation-menus/${navigation_menu_id}`), the response is too long, especially with multiple navigation levels.
- When "navigationMenuItems.customField" or "navigationMenuItems.link" or "navigationMenuItems.name", or all 3 fields together separated by comma as "navigationMenuItems.customFields,navigationMenuItems.link,navigationMenuItems.name", is searched using the "fields" parameter, everytime the response body returns only the first page, not the nested pages.
- How to restrict the response to only include "customFields", "name" and "link" fields, similar to how it's possible with the Web Content API.
- As per the expectation, when "navigationMenuItems.name" is searched, it should return all the nested pages, not only a single page.
Steps to reproduce:
- Login to Liferay DXP 2024.Q2.5.
- Create a navigation menu NM1.
- Create few content pages and add the pages into the navigation menu one under the other.
- Select the navigation menu and click Inspect to get the ID of the navigation menu.
- Open http://localhost:8080/o/api->GET/v1.0/navigation-menus/{navigationMenuId}) and use the provided API by replacing the Navigation menu ID with the NM1 ID.
- Under the "fields" parameter, enter "navigationMenuItems.customFields" or "navigationMenuItems.name" or "navigationMenuItems.link" and we can see that only the first page is returned and nested pages are not returned.



Environment
- Liferay DXP [all versions]
Resolution
- According to the product functionality, "fields" and "restrictFields" work by direct paths, which means that when dealing with nested entries, users need to specify the exact path of those fields to be able to display them.
- The "nestedFields" functionality is for another purpose. In the APIs, there can be some fields flagged as "Nested Fields" that would not be returned by default. They will only be returned once declared in the nestedFields query parameter.
- The "restrictFields" query parameter works the same way as the fields functionality works, but the other way around. This means that users need to use the direct pathing in the same way as with the fields parameter.
- There is a feature enhancement request for this requirement, which is being tracked under LPD-49192, but as decided by the Product team, currently, implementing this functionality is not on the product roadmap. If it is considered in the future, the team will first assess its feasibility and evaluate potential performance implications.
- Therefore, the recommended best practice for achieving this functionality is to handle the filtering at the client's end rather than expecting the API to return only the desired fields. This approach involves retrieving the full response and then extracting the necessary fields post-processing.
- If the client wishes to proceed with the above recommended approach, they can get in touch with the Sales Representative to see if they can set up a consultation with the Global Services Team as this request falls under Customizations.
did-this-article-resolve-your-issue