AI OnAI Off
For anyone interested, add controllers as services in your startup when calling AddMvc:
This allows you to inject EPiServer.ContentApi.Cms.Controllers.Internal.ContentController in your own controller.
Then you can get the converted object in your custom controller as follows:
var header = contentService.GetHeader();
var queryParameters = new ContentQueryParameters
{
References = $"{header.ContentLink.ID}"
};
var result = contentController.QueryContent(languages, queryParameters);
Some attributes are not respecting camel case, but it works otherwise.
This is probably not official / supported since it's calling internal classes, etc.
For a headless site, if I want to get data for a navigation block I can call the content api and get the full json for it:
/api/episerver/v3.0/content/123
This returns around 3k (formatted) json lines.
I instead want to make it independant from the ID. I have created a custom controller in the following path: /api/client/nav
I call a custom converter:
Which I can invoke
The caveat is that, since I'm not in content api, I have to manually create a ContentMappingContext.
This works and gets me the block. However, the problem is it does not apply any filters or auto expand for the properties. So we get 600 lines of (formatted) json. None of the navigation is expanded.
Here the documentation for auto expand for content area: https://docs.developers.optimizely.com/content-management-system/v1.5.0-content-delivery-api/docs/customizing-conversion-from-icontent-to-contentapimodel
Is there a simpler way to achive this? If not, we can just fix the IDs on the FE side but it would ideally be generic.