Sunday 6 August 2023

AEM Content Fragments using Assets HTTP API - Postman Collection

Adobe Experience Manager (AEM) is a powerful content management system that empowers marketers and content creators to manage digital assets efficiently. One of the key features in AEM is Content Fragments, which allows users to create and manage reusable content elements across different channels. In this blog post, we will explore AEM Content Fragments and how to interact with them using the Assets HTTP API.

What are Content Fragments?

Content Fragments in AEM are content elements that represent modular, structured pieces of content. They are designed to be used across multiple pages, channels, and websites, ensuring consistent messaging and branding. Unlike regular assets, Content Fragments are intended for reuse and are not meant to be published as standalone pages.

Advantages of Content Fragments:

  1. Reusability: Create once, use anywhere – Content Fragments can be used across multiple pages, campaigns, or even different AEM instances.
  2. Centralized Management: AEM provides a central location for managing Content Fragments, allowing for easy updates and versioning.
  3. Structured Content: Content Fragments are based on predefined models, enforcing consistency in the content structure.
  4. Multilingual Support: Easily manage multilingual content using different variations within a single Content Fragment.

Interacting with AEM Content Fragments using Assets HTTP API

AEM provides an HTTP API, specifically the Assets HTTP API, to interact with various asset types, including Content Fragments. Below are some common operations using the Assets HTTP API to manage Content Fragments programmatically.

  1. Create a Content Fragment: To create a new Content Fragment, make a POST request to the appropriate endpoint, providing the required metadata and elements in the request body. The Content Fragment will be stored as a JSON structure.
POST /api/assets/myfolder/myfragment
Authorization: Bearer {{your_access_token}}
Content-Type: application/json

{
  "jcr:primaryType": "dam:Asset",
  "jcr:content": {
    "jcr:primaryType": "dam:AssetContent",
    "jcr:mimeType": "application/vnd.adobe.fragment+json",
    "data": {
      "elements": {
        "title": "My Content Fragment",
        "description": "This is a sample content fragment.",
        "myCustomField": "Custom value"
      }
    }
  }
}

  1. Retrieve Content Fragment Metadata: To fetch the metadata of a specific Content Fragment, make a GET request to the corresponding endpoint.
GET /api/assets/myfolder/myfragment Authorization: Bearer {{your_access_token}}

  1. Update Content Fragment Metadata: To update the metadata of an existing Content Fragment, make a PUT request with the updated metadata in the request body.

PUT /api/assets/myfolder/myfragment
Authorization: Bearer {{your_access_token}}
Content-Type: application/json

{
  "jcr:primaryType": "dam:Asset",
  "jcr:content": {
    "jcr:primaryType": "dam:AssetContent",
    "jcr:mimeType": "application/vnd.adobe.fragment+json",
    "data": {
      "elements": {
        "title": "Updated Title",
        "description": "This is an updated content fragment.",
        "myCustomField": "New value"
      }
    }
  }
}

  1. Delete Content Fragment: To remove a Content Fragment, make a DELETE request to the corresponding endpoint.
DELETE /api/assets/myfolder/myfragment Authorization: Bearer {{your_access_token}}

Conclusion

AEM Content Fragments are a powerful feature that streamlines content management and promotes content reuse across various channels and campaigns. Leveraging the Assets HTTP API, developers can efficiently interact with Content Fragments programmatically, enabling seamless integration with external systems and applications.

By understanding the basics of Content Fragments and mastering the Assets HTTP API, organizations can create a more agile and scalable content management process, ensuring consistent and engaging digital experiences for their audiences.

Postman collection For AEM Content Fragments is published here.

No comments :

Post a Comment