Try our conversational search powered by Generative AI!

Remove HTML tags from Content API response

Vote:
 

I appreciate any and all help/tips to nudge me in the right direction. We are using Episerver 11.20.

We recently installed the Content Search API for the benefit of a mobile app dev team. However, there is an issue with HTML tags getting returned by the API in property fields, when we would prefer to discard them.

I checked some documentation instructions and I decorated the class property like so:

 [RemoveHtmlTagsWhenIndexing]
        public string NoticeDescription { get; set; }

In ClientInitialization.cs there is also this:

// Remove HTML tags
            conventions.ForInstancesOf<object>()
                .FieldsOfType<string>().StripHtml();

However, HTML tags are still returned in the API response like so:

noticeDescription": {
"value": "We will send more information as soon as possible. We apologise for the inconvenience.<br /><br /></p>\n<p><br /><br /></p>\n<p> </p>\n<p> </p>\n<p> </p>",
"propertyDataType": "PropertyXhtmlString"
},

If anybody has wrestled with the same issue, I'd appreciate any tips. Is there a way to easily customize the API response?

#297309
Feb 27, 2023 10:51
Vote:
 

You will need to use a Property Model Mapper : https://docs.developers.optimizely.com/content-cloud/v1.5.0-content-delivery-api/docs/serialization#property-model-mappers 

Using these methods you can customise the output of the JSON Payload. 

An example of how i used this to get Property Lists to work can be seen here : Optimizely-ContentDelivery-Examples/BenefitItemListPropertyConvertor.cs at b5226d372abd382d2775eeb530bfbe894b5f11b8 · Netcel-Optimizely/Optimizely-ContentDelivery-Examples (github.com) 

#297313
Feb 27, 2023 11:42
Minesh Shah (Netcel) - Feb 27, 2023 18:02
@Eetu So sorry in the rush of reading your message I thought you wanted to customize the Content Delivery API response. Reading it in a bit more detail I am not sure if this will work with the Content Search API. I'll have a quick look to see how to achieve this via a convention
Vote:
 

Thank you very much Minesh, I will look into these.

#297314
Feb 27, 2023 11:43
Vote:
 

I ended up creating a new controller to serve the mobile frontend that needed this content without the HTML formatting.

#298287
Mar 14, 2023 7:02
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.