London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Content Delivery API: customize returned data for blocks in content areas

Vote:
 

Hi,

The following article in the official documentation explains how to customize the API to change the data returned to clients: https://world.episerver.com/documentation/developer-guides/content-delivery-api/how-to-customize-data-returned-to-clients/

We have followed the instructions in the article, and are able to change the returned data for pages and blocks when they are the content being requested through the API, e.g. "/api/episerver/v2.0/content/<page or block identifier>". The same goes for using friendly URLs for pages, e.g. "/path/to/page".

However, we have not found a way to change the data returned for blocks that are contained in a content area (either in a page or in a block). Does anyone have any tips for how we can go about doing this?

- Thomas

#206980
Sep 05, 2019 8:26
Vote:
 

Hi, from ContentDeliveryApi 2.9.0, you can use the ContentApiModelFilter to modify the model before return to client. Some basic steps:

  • Create a custom filter class that inherits from ContentApiModelFilter, then mark it with the ServiceConfiguration attribute: [ServiceConfiguration(typeof(IContentApiModelFilter), Lifecycle = ServiceInstanceScope.Singleton)]
  • Override the method Filter. In this method, you can looking for the block inside the ContentAreaPropertyModel of the content api model and modify the Value/ExpandedValue as you want
#219265
Apr 01, 2020 6:52
* 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.