Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Strengthen eCommerce With SAP Hybris and Anypoint Platform

DZone's Guide to

How to Strengthen eCommerce With SAP Hybris and Anypoint Platform

Learn how you can use MuleSoft and the Anypoint Platform for eCommerce to create a unified view of a single customer across channels.

· Integration Zone
Free Resource

The Integration Zone is brought to you in partnership with Cloud Elements. What's below the surface of an API integration? Download The Definitive Guide to API Integrations to start building an API strategy.

The importance of eCommerce is expanding rapidly, especially with Amazon continuing to build its robust platform. Online sales will reach $414 billion by 2018 and mobile commerce now accounts for 21% of total digital sales. Given the growing importance of eCommerce as a channel, it is imperative that eCommerce works seamlessly with a retailer’s traditional channels.

Typical eCommerce platforms today tightly couple their technology layers, inhibiting any flexibility to drive omnichannel experiences. Fortunately, 2 of the top 5 global retailers leverage MuleSoft to serve as their connectivity layer––unlocking flexibility, customization and personalized shopping experiences for their consumers.

One of the key use cases for organizations is how to achieve that valuable view of a customer across channels, often referred to as “Single View of the Customer.” For many organizations, however, obtaining this comprehensive view is challenging; it requires connecting different systems in real-time when an event happens.

As the customer data needs to go everywhere – not just to a single Customer Relationship Management system (CRM) or a single Order Management System (OMS) system – an organization needs to have APIs and a reliable backbone for domain events.

MuleSoft is helping organizations build a single view of the customer by introducing reusable APIs and the Anypoint MQ cloud message broker. Leveraging Anypoint Platform, customers can have a seamless integration of their eCommerce solution, such as SAP Hybris, with their CRM Solution, in order to unlock a comprehensive customer view. 

SAP Hybris Connector

SAP Hybris is a complete customer engagement and multi-channel eCommerce solution with fully integrated tools and capacities. It serves B2B and B2C brands across industries such as financial services, telecommunications, insurance, media, manufacturing, retailing and wholesale. This connector was built by our valued partner, Apisero.  

How to Build a Single View of the Customer

In this How-To, we’ll present a demo showing how a customer address domain event can be handled in MuleSoft using API-led Connectivity and Anypoint MQ. Additionally, we’ll show how to orchestrate data from multiple sources to fetch a single view of a customer.

A faux company, Muletailer, uses Salesforce (SDFC) as their CRM and SAP Hybris for eCommerce. All interfaces to SFDC and SAP Hybris will be exposed through reusable API interfaces. One of Muletailer’s biggest challenges is keeping address changes up to date in real-time across multiple on-prem and SaaS data stores.

As customers are doing more account management on disparate channels/apps, Muletailer wants to make sure customers can change their information across channels, at any time, and propagate it in real-time across any application that holds customer information.

We’ll start by building our SFDC System API (for more information on what is a System API, check out page 4 of this resource).

Salesforce System API:

In this How-To, we’re only going to require access to get and update customer info, but the attached project will include more verbs such as Delete and Post.

MuleSoft and SAP

1. For the first Verb: get:/sfdc-contact/{user-id} we’ll only need the Salesforceand DataWeave.  Upon connectivity to Salesforce, we’ll simply use the SFDC query builder to fetch the fields from the Contact object that we need.  

Salesforce Query:  

SELECT AccountId,Department,Description,Email,FirstName,Id,LastName,MailingCity,MailingCountry,MailingPostalCode,MailingState,MailingStreet,Name,Phone FROM Contact WHERE Email = '#[flowVars.userId]'

#[flowVars.userId] is an MEL expression that grabs the inbound value that came in on the URI of the API call – which represents the customer UserID in Salesforce.

2. Now that we have the response in a Map, using the DataWeavetransformer, we need to conform the response into JSON and match the RAML API contract for the SFDC system API.

% dw 1.0

 % output application / json

-- - {
 firstName: payload.FirstName,
 lastName: payload.LastName,
 phoneNumber: payload.Phone,
 email: payload.Email,
 sfdcContactId: payload.Id,
 address: [{
  "Mailing City": payload.MailingCity,
  "Mailing Country": payload.MailingCountry,
  "Mailing PostalCode": payload.MailingPostalCode,
  "Mailing State": payload.MailingState,
  "Mailing Street": payload.MailingStreet
 }],
 date: now
}

3. Our next step will be exposing a PUT operation on the Customer resource to provide a reusable way to change data in our Salesforce Contact Object.

MuleSoft and SAP

To implement this flow: PUT /sfdc-contact/{userId} we’ll use 2 transformers to receive the inbound JSON and map to the Salesforce Connector.  To perform an update, the only required field is SFDC contact ID and the additional data fields that need to be updated.  For this How-To, I’m only exposing the ability to change the Address block in the Contact Object, so in my Dataweave (json>> java Map) I’m only mapping those fields.

Example:  

% dw 1.0

 % output application / java

-- - [{
 Id: payload.sfdcContactId,
 MailingStreet: payload.address[0].
 "Mailing Street",
 MailingCity: payload.address[0].
 "Mailing City",
 MailingState: payload.address[0].
 "Mailing State",
 MailingPostalCode: payload.address[0].
 "Mailing PostalCode",
 MailingCountry: payload.address[0].
 "Mailing Country"
}]

For the response, I’m just setting a hardcoded JSON value. This, of course, could be dynamic.

4. So now we’ve built a reusable System API in front of our Salesforce Contact API. Before we go ahead and expose a Customer API that consumes/writes Salesforce Customer information, we’ll want to add one more piece of functionality to this Mule app – ingesting any Customer address changes that are published to Anypoint MQ. We now have our System API Mule app listening to a dedicated queue for any Customer Address changes that need to get propagated in Salesforce.

To do this, we’ll go to File >> New Mule Configuration file in Anypoint Studio. Add 3 components: Anypoint MQ  Connector (to subscribe to Anypoint MQ queue), Dataweave transformer (to transform Customer Address event to SFDC API), Flow Reference (to call PUT:/customer/{customerId}. (Within Anypoint Platform, you’ll need to have access to the Anypoint MQ module in order to set up a queue.)

MuleSoft and SAP

That’s it! We now have an API for interfacing with Salesforce Contact data and a way to ingest customer domain events for address changes.

Catalyst Accelerator for Retail – Customer API

I went ahead and downloaded the latest Catalyst Accelerator for Retail RAML definition to expose my Customer API. These RAML contracts are based on API best practices, specifically in the Retail Vertical (to learn more about the pre-packaged set of retail assets, check out Catalyst Accelerator for Retail).

Using our out-of-the-box RAMLs allows your delivery team to focus less on API Design and jump right into implementation. For the implementation, all write operations (POST, PUT, DELETE) will go to SAP HYBRIS OCC and providing a successful transaction will broadcast the customer event to Anypoint MQ – where our subscribers can pull in the event and update their apps/data stores. For querying data, we’ll source data from multiple sources: SAP Hybris and our reusable SFDC Contact API.

PUT:/customers/{customerId}

MuleSoft and SAP

DataWeave:  Since I’m using Catalyst Accelerator for Retail, I do not have to define my inbound API contract (phew!), I only have to map the inbound JSON body to Hybris OCC.

Hybris Omni Channel Commerce Connector:  You’ll notice in the connector, I’ve used MEL expressions to pull in the inbound JSON from the client for the following fields: titleCode, First Name, Last Name, Line1, Town, Postal Code, IsoCode

Response Transform:  Used to hard code the response back to the consumer.

Asynch: I’ve wrapped the domain event into an Asynch scope to avoid the event publishing blocking the synchronous transaction of the PUT request.

a) Set Payload: copies the inbound JSON sent in on the call and sets the payload for the Anypoint MQ Publish

b) Anypoint MQ Publish: pushes JSON payload to Anypoint MQ.  Please note, this is going to an Exchange where potentially multiple queues can be added.  This allows Muletailer to add more and more SAAS apps, data stores, etc. to the message exchange without having to change/redeploy and Mule APIs/Apps.

Summary: PUT:/customers/{customerId}

So we now have PUT resource receiving all Customer Information changes >> pushing into Hybris and then broadcasting a domain event to AnyPoint MQ. This allows Muletailer to add new subscribers to this message event without updating the API. Please see how to configure queues and exchanges by reading the following documentation.  

Lastly, Muletailer needs to expose a single view of each of their customers. To do this, we’re using GET: /customers/{customerId} API call orchestrate data from Salesforce and Hybris to return a single view.

MuleSoft and SAP

  • Scatter Gather: Fires off to requests to Hybris and Salesforce

  • Hybris Connector:  Gets order History by UserId in Uri

  • HTTP Connector:  reuses SFDC system API built previously.

  • DataWeave:  

    • transform2json:  Transform Hybris Map to JSON

    • return JSON response:  sources both payloads into one unified response (based on RAML contract)

Summary  

In this How-To guide, we have demonstrated how easy it is to use the SAP Hybris Connector, our newest addition to the MuleSoft Connector family. We now have an API that provides a single view of a customer’s account information and order history – all in one API. Of course, this API could be extended to include more customer information such as rewards, payment methods, etc.

With this demo, we have built a foundation to allow Customer address changes to be distributed to a messaging backbone. All API artifacts are reusable for the next project.

Connector Details

Omni Commerce Connect, part of SAP Hybris, offers a broad set of commerce and data services, which allows users to leverage the complete Hybris Multichannel Suite functionality to quickly enable new touch points and new channels. OCC empowers organizations to expose key commerce capabilities via a RESTful Web service API.

OCC exposes the following key commerce capabilities to the clients:

  • Catalog Data
  • Search and Navigation
  • Customer Management
  • Product Information
  • Cart and checkout functionality
  • Orders

Using MuleSoft’s Anypoint Platform, the Anypoint SAP Hybris connector enables retailers to integrate their existing applications with SAP Hybris by leveraging the Omni Channel Commerce V2 REST APIs provided by SAP.

Here are some operations currently supported (for a full list view here):

  • Create user address by userId
  • Get products
  • Adds a product to the cart
  • Selected Delivery Mode Of Cart
  • Return Saved Cart User By Id
  • Get Customer Group Of Customer List
  • Get Count Of Order Placed By Specified User
  • Return Order History Data By User Id

Github Assets

  1. Salesforce System API and Message ingester 
  2. Retail Catalyst API

Ready to get started? Check out these resources!

Your API is not enough. Learn why (and how) leading SaaS providers are turning their products into platforms with API integration in the ebook, Build Platforms, Not Products from Cloud Elements.

Topics:
anypoint platform ,anypoint connector ,mulesoft ,sap ,integration ,enterprise

Published at DZone with permission of Jay Parisi. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}