Custom properties on media items missing in Content Delivery API response
Hi! I'm setting up a brand new Umbraco 13 API with the Content Delivery API enabled. My issue is that images that are selected with the media picker on a document type only returns the default properties of that image . Any additional properties (Alt Text e.g.) I add to the Image media type are ignored.
If I retrieve the image through the Media Delivery API then I do indeed get the custom properties, but I'd rather avoid doing extra calls to the API since I already have all the info except for a single property in the response from the CDA.
Am I just fetching the data incorrectly? I've tried using the expand parameter but that didn't work. Or do I indeed have to make extra calls to the api to get the missing data?
In our non-headless solutions we could access alt text via @image.UmbracoAlt, which would come through in the SSR request.
For our headless solutions which leverage the Content Delivery API, we run into that same problem and alt text can't seem to be retrieved for an image in the same request as the content data. The properties key is just left blank.
It would be great if the alt text could be returned in the same call, but beyond making additional Media Delivery API requests, we aren't sure how.
Well... I managed to do overcome this. I created my custom implementation of IApiMediaBuilder and IWebhookOutputExpansionStrategy and replaced the original services with them.
Matesuz Kowica, could you give us a code example of your implementation? We are currently facing the same problem with custom properties like alt-text.
I will not post the exact code as it is mainly copy-paste from the original Umbraco code, but I can guide you how I done it, so you will be able to recreate it easily on your own.
And one disclaimer - I needed it for adjusting the webhook payload not API calls, but I believe the same code is used underneath to construct the result payload for both use cases, so I hope my workaround will also work for you :)
So!
After investigation it occurred that the root cause of the problem with missing custom media properties sits inside RequestContextOutputExpansionStrategyV2 class, especially I mean here the forceExpandProperties argument which is defaulted to false for content API.
The first idea here was to create my own implementation for IOutputExpansionStrategy where I would add a support for extended properties coming from Media documents. Unfortunately I learned that for media properties the content serialization is called from ApiMediaBuilder and the reference is resolved using IOutputExpansionStrategyAccessor where I could not find any way how to overcome the logic to inject my own implementation of IOutputExpansionStrategy without messing with DI too much.
That is why I decided to create my own implementation of, firstly, IOutputExpansionStrategy where I added support for extended properties, and secondly - for IApiMediaBuilder where I injected my custom IOutputExpansionStrategy implementation. The last step is just to swap the registration in the Di container during Umbraco startup.
As mentioned earlier - it's not too elegant, but it works like a charm.
I also faced this issue with the Content Delivery API not returning custom properties like Alt Text. It would be great if Umbraco could include these properties in the same call to avoid extra API requests. Hoping for a future update to address this
My bad, that i didn't read the documentation properly the first time around ;)
My expansion for a blockGrid Editor with some layouts and areas and different kinds of blocks, that might have image properties in them was:
properties[contentBlockGrid[properties[$all]]]
Custom properties on media items missing in Content Delivery API response
Hi! I'm setting up a brand new Umbraco 13 API with the Content Delivery API enabled. My issue is that images that are selected with the media picker on a document type only returns the default properties of that image . Any additional properties (Alt Text e.g.) I add to the Image media type are ignored.
If I retrieve the image through the Media Delivery API then I do indeed get the custom properties, but I'd rather avoid doing extra calls to the API since I already have all the info except for a single property in the response from the CDA.
Am I just fetching the data incorrectly? I've tried using the
expand
parameter but that didn't work. Or do I indeed have to make extra calls to the api to get the missing data?Umbraco version: 13.1.0
Content Delivery API
:Media Delivery API
:In our non-headless solutions we could access alt text via
@image.UmbracoAlt
, which would come through in the SSR request.For our headless solutions which leverage the Content Delivery API, we run into that same problem and alt text can't seem to be retrieved for an image in the same request as the content data. The properties key is just left blank.
It would be great if the alt text could be returned in the same call, but beyond making additional Media Delivery API requests, we aren't sure how.
Hey Robert,
have you found a solution to your problem? I face exactly the same issue.
Hey Mateusz, I'm afraid I haven't found a solution to this yet. Hoping this feature will eventually get added to the Delivery API.
We also face the same problem and would like to avoid making a call to the Media API just to get ALT Text.
Well... I managed to do overcome this. I created my custom implementation of
IApiMediaBuilder
andIWebhookOutputExpansionStrategy
and replaced the original services with them.Not really elegant but efficent :)
Matesuz Kowica, could you give us a code example of your implementation? We are currently facing the same problem with custom properties like alt-text.
I will not post the exact code as it is mainly copy-paste from the original Umbraco code, but I can guide you how I done it, so you will be able to recreate it easily on your own.
And one disclaimer - I needed it for adjusting the webhook payload not API calls, but I believe the same code is used underneath to construct the result payload for both use cases, so I hope my workaround will also work for you :)
So!
After investigation it occurred that the root cause of the problem with missing custom media properties sits inside
RequestContextOutputExpansionStrategyV2
class, especially I mean here theforceExpandProperties
argument which is defaulted tofalse
for content API.The first idea here was to create my own implementation for
IOutputExpansionStrategy
where I would add a support for extended properties coming from Media documents. Unfortunately I learned that for media properties the content serialization is called fromApiMediaBuilder
and the reference is resolved usingIOutputExpansionStrategyAccessor
where I could not find any way how to overcome the logic to inject my own implementation ofIOutputExpansionStrategy
without messing with DI too much.That is why I decided to create my own implementation of, firstly,
IOutputExpansionStrategy
where I added support for extended properties, and secondly - forIApiMediaBuilder
where I injected my customIOutputExpansionStrategy
implementation. The last step is just to swap the registration in the Di container during Umbraco startup.As mentioned earlier - it's not too elegant, but it works like a charm.
I hope it helps!
I also faced this issue with the Content Delivery API not returning custom properties like Alt Text. It would be great if Umbraco could include these properties in the same call to avoid extra API requests. Hoping for a future update to address this
I solved my problem now by trying property expansion again (Documentation: Property Expansion for Block Grid)
My bad, that i didn't read the documentation properly the first time around ;)
My expansion for a blockGrid Editor with some layouts and areas and different kinds of blocks, that might have image properties in them was: properties[contentBlockGrid[properties[$all]]]
so in the call it is:
is working on a reply...