Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Content fragment JSON api: "../my-fragment.model.json" returning 'Bad Request'

Avatar

Level 1

I'm attempting to use the JSON exporter to retrieve the contents of a content fragment as JSON but have encountered a few issues. Would you have advice on how best to directly retrieve the content of a content fragment in JSON format? Note that I am not accessing a page which contains the content fragment, I am attempting to directly access the content fragment itself.

 

1. Accessing "../my-fragment.json" returns the basic jcr info, but ../my-fragment.model.json throws a '400 (Bad Request)' error. Is something wrong, or is that expected?

 

2. I also looked into using the Assets API, which works from the author (like in the link below), but not from the dispatcher, which is how I would want to use it for front-end / client-side use of the JSON endpoint.

https://localhost:4502/api/assets/my-path/my-fragment.json

 

The only way I've managed to access the content fragment in JSON format is "../my-fragment/jcr%3Acontent/data/master.json" but this includes the lastUpdated value of each variable and I have not seen any AEM documentation reference this method

 

Thank you!

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @Jesse-CU 
my-fragment.model.json would work, if a Sling Model is associated with the "my-fragment". If it had been a Content Fragment Core Component carrying a CF rendered on a Page, this my-fragment.model.json would have worked.

But Content Fragments are essentially Assets, which are accessible via Asset HTTP API.
Assets HTTP API should work seamlessly if CFs and their respective CF Models are published and that they are no dispatcher rules against this API.
Eg

krati_garg_0-1681235488957.png



View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

Hi @Jesse-CU 
my-fragment.model.json would work, if a Sling Model is associated with the "my-fragment". If it had been a Content Fragment Core Component carrying a CF rendered on a Page, this my-fragment.model.json would have worked.

But Content Fragments are essentially Assets, which are accessible via Asset HTTP API.
Assets HTTP API should work seamlessly if CFs and their respective CF Models are published and that they are no dispatcher rules against this API.
Eg

krati_garg_0-1681235488957.png