How would I go about adding new custom fields I have created for CMS pages to M2.4.2 CMS REST API responses (and possibly even search/filtering)?

For example, if I want to add new fields to retrieving a single CMS page response, and retrieving a multiple CMS pages meeting certain criteria (possibly even filtering by these new fields if possible?) response?

For example, here are my new fields (a text field and a date field) which are saved in the database: https://i.sstatic.net/0tqea.png

I added them in InstallSchema: https://i.sstatic.net/utfe9.png

and in UpgradeSchema: https://i.sstatic.net/gukqz.png

I also added them in the adminhtml ui_component xml: https://i.sstatic.net/HoMgW.png

If someone could help me retrieve these new fields (and maybe even search by these new fields) in API call responses (get single CMS page and get multiple CMS pages) that would be amazing.

For example, I want to add new fields to this REST API response: https://i.sstatic.net/XDRLF.png

Also I would like to add new fields to this REST API response: https://i.sstatic.net/Ryljp.png

Thank you.

1 Answer 1


You can use a plugin to add value in API's return result

The handler function in the

api /V1/cmsPage/:pageId is vendor/magento/module-cms/Model/PageRepository.php:217

you should use the after plugin in the function getById, then use the setData function to add your value to the returned result

  • Funnily enough, I did try exactly that a couple weeks ago, but it doesn't seem to be working: i.imgur.com/IwEJrCU.png It does add the data to the Object, and it can even for example successfully save it to the database when calling the save method, but the API never actually returns the new result. I don't think what I want to accomplish is possible, I don't think the existing (CMS or other) APIs are meant to have top-level attributes added to them nor is it possible.
    – drgandynt
    Jan 4, 2022 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.