This post was originally published on this site

Overview

This document will explain Contentful CMS integration with SAP Commerce which includes implementation of Mulesoft as a Middleware for routing and transforming messages.

The behaviour of this implementation will work as a single application where content writers can insert some content for products and categories in Contentful which will be pushed to SAP Commerce passing through Mulesoft.

Contentful CMS Introduction

Contentful is all about content. From web apps to billboards, It makes sure that your content gets delivered via CDN in a flash. But before any content can be delivered to apps, It needs to create a data model for it. Much like a database table, a content model lets you define what type of content you want to store and once this is ready the content is delivered to other systems through Contentful REST APIs called as Content Delivery API(CDA) and Content Management API(CMA).

 

How This Integration Works

There’s some explanation for the flow of integration defined below:

  1. Content writer adds/modifies content in Contentful Entry which is then triggered by Contentful Webhook
  2. Webhook then notifies with payload to Mulesoft
  3. Mulesoft transforms Contentful payload to SAP Commerce payload
  4. Mulesoft requests SAP Commerce Platform Webservices with payload as body to insert category or product
  5. SAP Commerce Platform Webservices then persists data in SAP Commerce platform and in response status code is sent to Contentful Webhook Passing though Mulesoft.

Technical Implementation

There are some steps to prepare systems before integration:

Prepare Systems

1. Contentful

  • Create a Contentful CMS account and then a “space” inside your account
  • Create “content model” and add “fields” in that model which is a sort of Database table and columns
  • Create some “content entries” in that model which can be supposed as Table Row
    Let’s suppose there are 3 fields in a content model which should look like the image below

2. SAP Commerce

  • Create catalog and catalog versions which would contain category and products
  • Add platformwebservices extension in localextensions.xml
  • ant clean all and verify if platformwebservices extension working

3. Mulesoft

  • Create an application project in mulesoft
  • Create a flow and chain defined connectors
    1. HTTP Listener
      1. This will behave as entry point of the flow and will be used to receive payload from Contentful webhook
    2. HTTP Request
      1. This will be used to request and receive full payload for particular category including its supercategories
    3. Transform
      1. This will be used to transform Contentful payload to SAP Commerce payload
    4. HTTP Request
      1. This will be Used to Send data to SAP Commerce

Integrate Systems

1. Configure Settings in Contentful Application for Integration

  1. Create Webhook in Contentful Application and go to Settings → Webhooks
  2. Configure settings as defined in images below

 

Note :

  • URL field should be cloud hub URL where Mulesoft Application is deployed before /category
  • As defined in image, this webhook is configured for the entry of Category content type
  • Now when any record is inserted in Category model at the same time this Webhook would be triggered and data of that entry would be sent to Mulesoft
2. Configure Settings in Mule Application for Integration
Now we’ll configure connectors in Mulesoft Application which were created in “Prepare Systems” section

  1. HTTP Listener
    1. Define method as POST
    2. Define path as /category
  2. HTTP Request
    1. Define Method as GET
    2. Define URL as:
      https://cdn.contentful.com/spaces/<SPACE_>/entries/?access_token=<ACCESS_TOKEN>&content_type=category&include=1&fields.categoryCode=payload.fields.categoryCode.”en-US”
    3. Define Request body as payload
  3. Transform
    1. Transform Contentful payload to SAP Commerce payload
  4. HTTP Request
    1. Define method as PUT
    2. Define URL as https://{host}/ws410/rest/catalogs/<Catalog>/catalogversions/<CatalogVersion>/categories/payload.code

Once done with the steps defined above, Add any category in Contentful then Publish it, and go to SAP Commerce Backoffice to verify the category.

Summary

As this integration works perfectly fine for products and categories, using mulesoft was an idea to not make any basic customisations in SAP Commerce however it can be achieved using Contentful API libraries like CMA and CDA by customising SAP Commerce Service layers and CronJobs. This Integration can be enhanced to make it work for assets integration for which there might be some customisation required in SAP Cmmerce to import external media.

This story originally appeared on and is accredited to SAP Hybris Blogs (Official)