Expand my Community achievements bar.

SOLVED

how to retrieve content fragment data

Avatar

Level 2

How to Implement a backend API or service to fetch content fragments from the CMS

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @ssin93 ,

There are two ways through which you can achieve this:
1. Use AEM’s GraphQL APIs for Content Fragments which supports headless CMS scenarios wherein external client applications render experiences using content managed in AEM.

Checkout this article for more details on it:
https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-with-aem-headless/g...

2. Write your custom servlet which will invoke a service class that in turn will return the JSON data from Content fragment.

3. Make your content fragment adaptable through sling model and use exporter in it.

I'd recommend you to go for the first AEM Graph QL.


Thanks
Tarun

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @ssin93 ,

There are two ways through which you can achieve this:
1. Use AEM’s GraphQL APIs for Content Fragments which supports headless CMS scenarios wherein external client applications render experiences using content managed in AEM.

Checkout this article for more details on it:
https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-with-aem-headless/g...

2. Write your custom servlet which will invoke a service class that in turn will return the JSON data from Content fragment.

3. Make your content fragment adaptable through sling model and use exporter in it.

I'd recommend you to go for the first AEM Graph QL.


Thanks
Tarun

Avatar

Community Advisor

@ssin93 Below is a design suggestion on implementing the API to read content fragment 

  1. API Endpoint Design:

    • Design the API endpoints that you will use to fetch content fragments. Decide on the URL structure and naming conventions for your API.
  2. Create Backend Routes:

    • Implement the backend routes or endpoints in your API server. These routes will handle incoming requests and communicate with the CMS to fetch content fragments.
  3. CMS Integration:

    • Integrate your backend with the CMS API. Depending on the CMS, this may involve making HTTP requests to specific CMS endpoints or using CMS-specific SDKs or libraries.
  4. Data Mapping:

    • Define how content fragment data should be mapped to your API's response format. You may need to transform and format the data before sending it as a response.

Avatar

Community Advisor

Hi @ssin93 

 

What is your use case here?Like where you need this CF data as in a Component using Sling Model or at some other place?

We have implemented a similar service where we pass CF path and it will retrive all the Content in JSON format and can be used anywhere.

 

Let me know if I I can help further on this.

Avatar

Community Advisor

@ssin93 ,

There are multiple ways to retrieve content fragments data based on the use case. Please see below the OOTB approaches to retrieve the CF data and export as JSON.

1) AEM GraphQL API: https://experienceleague.adobe.com/docs/experience-manager-65/assets/content-fragments/content-fragm...

 

2) Content Fragments using Assets HTTP API: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/assets/admin/assets...