cancel
Showing results for 
Search instead for 
Did you mean: 

How to add new fields to M2.4.2 CMS API response?

How to add new fields to M2.4.2 CMS API response?

Hi,

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.imgur.com/QLYcLKc.png 


I added them in InstallSchema: https://i.imgur.com/PukFQDN.png 

and in UpgradeSchema: https://i.imgur.com/cE30JEM.png 


I also added them in the adminhtml ui_component xml: https://i.imgur.com/pImRL5f.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.

Thank you.

6 REPLIES 6

Re: How to add new fields to Magento 2.4.2 CMS API response?

Hello @drgandynt,

 

Greetings to you!

 

I understand your issue. You need to override the default APIs and then you can create an extension. This is the only way to do it.

 

I hope this will help you.

If not, feel free to contact us.

If worked, click KUDOS and accept it as a solution.

 

Thank you!

Re: How to add new fields to Magento 2.4.2 CMS API response?

Hi @namitapare2a78,


I'm afraid it's not immediately clear how to do that - I don't really see any documentation about that. Which interface and methods would I override for the single and multiple CMS Page API responses? How would you recommend doing that, should I use a plugin (interceptor) and if so which type?

I would appreciate as much detail as you can provide.

Cheers.

Re: How to add new fields to Magento 2.4.2 CMS API response?

Hello @drgandynt,

 

Greetings!

 

We've already done this type of API issue. So we can develop a custom plugin. There is no ready-made plugin to integrate. 

 

If you want we can help you with that.

 

Looking forward to your response.

 

Thank you!

Re: How to add new fields to Magento 2.4.2 CMS API response?

Hi,

Are you talking about a Plugin (Interceptor) https://devdocs.magento.com/guides/v2.4/extension-dev-guide/plugins.html? That is what I was talking about. If this is possible to use for what I'm looking for then yeah I am interested in help with this, but I'm not interested in buying a custom module if that's what you're talking about. I want to develop this solution myself.

I'm not sure if I can use a Plugin (Interceptor) or what interfaces and methods to override for this, etc.

For example, I want to add new fields to this REST API response: https://i.imgur.com/gbKs4Zr.png

Also I would like to add new fields to this REST API response: https://i.imgur.com/k1Ha4Lm.png

 

I would appreciate as much help with this as possible.

Thanks.

Re: How to add new fields to Magento 2.4.2 CMS API response?

Hi @drgandynt,

Greetings of the New Year!

Sorry for the late.

Plugin (Interceptor) would not help you to fulfill your requirement. 

I'm sharing 1 reference. Kindly go through that and if you need any help feel free to contact us.

https://devdocs.magento.com/guides/v2.4/extension-dev-guide/extension_attributes/adding-attributes.h...

 

If worked, click KUDOS and accept it as a solution.

Thank you!

Re: How to add new fields to Magento 2.4.2 CMS API response?

Hi,

That's for products, though, so surely that wouldn't work for CMS pages since CMS pages (Page entities) don't support attributes of any kind (either extension or EAV), right?

Thanks.