how to retrieve content fragment data | Community
Skip to main content
Level 2
September 26, 2023
Solved

how to retrieve content fragment data

  • September 26, 2023
  • 4 replies
  • 2582 views

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

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 TarunKumar

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/graphql/overview.html?lang=en

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

4 replies

TarunKumar
Community Advisor
TarunKumarCommunity AdvisorAccepted solution
Community Advisor
September 26, 2023

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/graphql/overview.html?lang=en

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

Jagadeesh_Prakash
Community Advisor
Community Advisor
September 26, 2023

@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.
iamnjain
Community Advisor
Community Advisor
September 26, 2023

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.

Sudheer_Sundalam
Community Advisor
Community Advisor
September 26, 2023

@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-fragments-graphql.html?lang=en

 

2) Content Fragments using Assets HTTP API: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/assets/admin/assets-api-content-fragments.html?lang=en