Content fragment JSON api: "../my-fragment.model.json" returning 'Bad Request' | Community
Skip to main content
April 11, 2023
Solved

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

  • April 11, 2023
  • 1 reply
  • 1300 views

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!

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by krati_garg

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



1 reply

krati_garg
Adobe Employee
krati_gargAdobe EmployeeAccepted solution
Adobe Employee
April 11, 2023

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