CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
Showing results for 
Search instead for 
Did you mean: 

The SAP Cloud Applications Studio (also known as Partner Development Infrastructure / PDI or simply Software Development Kit / SDK) is widely used by customers and partners to create customer-specific extensions for SAP Hybris Cloud for Customer (C4C). Functional requirements which go beyond standard capabilities e.g. advanced UI, specific business logic, and data model enhancements etc. can be implemented using the SAP Cloud Applications Studio with embedded UI Designer tools.

For more information please visit and the community under You may sign-up for the partner program here:

In this blog, I am going to describe how you can integrate SAP Hybris Loyalty with SAP Hybris Cloud for Customer. SAP Hybris Loyalty enables organizations to create their own cloud based loyalty program and gain valuable consumer insights by offering points for signups, purchases, referrals, ratings and reviews. Consumers will collect points and redeem them for rewards to use at store, which encourages repeat visits and long term loyalty. In this example, we describe how you can visualize these customer loyalty points for your Sales Representatives in SAP Hybris Cloud for Customer (see screenshot below).


Now, let’s have a look into the technical implementation. First, for calling of any external web service, you must create a communication scenario definition and External Web Service definition. This is created in the SAP Cloud Applications Studio solution. You can provide a Web Service name and Web Service Type (in case of Hybris as a Service, the Web Service type is REST). Also, provide the URL for the Web service. For each communication scenario definition, you need to create Communication Arrangement in the C4C system or tenant on which you are building your solution. To call a ‘Hybris as a Service’ service, we need to create a communication arrangement for OAuth. We also need to create communication arrangement for the service which we are trying to consume.

For parsing of JSON response, we have created a library named Parser. For more information about this parser, see

For using the parsing logic, you can create a dummy custom BO with the following elements:
businessobject WebServiceParser {

// Dummy BO for the parser.

element RootElement : IntegerValue;

node Result [0,n] {
element ID : IntegerValue;
element ParentID : IntegerValue;

This is required to read the table line. It stores the parsed fields and its values.

To parse and return the values of fields, some enhancement was done to the parser.
var fieldValue ;
if ( field != "")
fieldValue = results.Where(n=>n.Name == field);
return fieldValue.GetFirst( ).Value;
return "";


To consume any ‘Hybris as a Service’ service, you must generate a bearer token which will be used for authorization. There are certain parameters which are required to be passed for generating an access token.

If grant_type is ‘client_credentials’, you must pass valid client_id, client_secret and scopes for generating a token. In case the grant_type is ‘password’,please provide Hybris as a Service username, password and scopes. For more information, please see .

Provide the Web Service name as the Scenario Name and Service Name. Provide the HttpMethod(GET, POST, PUT or DELETE)  which is supported by the service. You should specify all the header parameters required to make the service call. You can also provide URL parameters if required for the service call.

For calling the ‘Hybris as a Service’ OAuth service via SAP Cloud Applications Studio solution, you must create a communication scenario definition, External web service definition and communication arrangement. Pass all the parameters required for OAuth service call. You should form the body to be passed. In the below case, the token generation is for grant type client_credentials.
import ABSL;

// For the testing purpose we would take the loyalty member id and
//modify the loyalty points

var ScenarioNameOauth = "YaaSOauth";
var ServiceNameOauth = "YaaSOauth";
var HttpMethodPost = "POST";
var HttpResource = "";
var ContentTypeOauth = "application/x-www-form-urlencoded";
var HeaderParameter : NameAndValue;
var HeaderParameters : collectionof NameAndValue;
var URLParameters : collectionof NameAndValue;
var BodyOauth = "grant_type=&YaaSOauth_grant_type&&scope=&YaaSOauth_scope&&client_id=&YaaSOauth_client_id&&client_secret=&YaaSOauth_client_secret&";
var BearerToken;
var HttpMethodGET = "GET";
// Get the bearer token

HeaderParameters.Clear( );

// adding header parameter for the content type

HeaderParameter.Name = "Content-Type";
HeaderParameter.Value = "application/x-www-form-urlencoded";

// making webservice call for the bearer token
var ws_result = WebServiceUtilities.ExecuteRESTServiceWithoutEncoding

This blog explains the consumption of the ‘Hybris as a Service’ Loyalty Member service via SAP Cloud Applications Studio. I have extended the C4C Customer BO to add two extension fields on the UI – Loyalty Member ID and Loyalty Member Earned Points. When the user enters a valid Loyalty Member ID, it fetches the earned points for that member and displays it on the UI.




Creating SAP Cloud Applications Studio Solution:

To demonstrate the process, I have created an extension of C4C Customer BO, named LoyaltyCustomerData BO, which has two extension fields-  Loyalty Member ID and Loyalty Member Earned Points. These fields will be added to the Individual Customer TI using the Extensibility Explorer. When the user enters a Loyalty Member ID on the UI, it will call our SAP Cloud Applications Studio solution. Our solution in turn handles calling of the ‘Hybris as a Service’ OAuth service and Loyalty service and fetches the Earned Points for the member and displays it on the UI.
[Extension] businessobject AP.FO.BusinessPartner.Global:Customer {

node AddressInformation {

node Common {
// adding two dummy field for the demo purpose
[Label("Loyalty Member ID")] element LoyaltyMemberID : LANGUAGEINDEPENDENT_EXTENDED_Text;
[Label("Loyalty Member Earned Points")] element LoyaltyMemberPoints :

node CurrentEmployeeResponsible {


This BO has an after-modify event associated with it. In the communication scenario definition of OAuth, you can provide some API keys (for instance grant_type, scope, client_id and client_secret). These API keys will be passed in the body to create a token. The values of these API keys are defined in the communication arrangement and is thus specific to that C4C system or tenant. The values of the API keys are replaced by the ones provided in the C4C system during runtime.

If the response returned from the ‘Hybris as a Service’ OAuth service is a success, call the ‘Hybris as a Service’ Loyalty Member service. You must pass this generated access token as header for calling the ‘Hybris as a Service’ Loyalty Member service. Create a communication scenario definition and an External Web Service definition. Also, create a communication arrangement in the system in which this solution is built on. The Loyalty Member ID to be entered from the UI should be passed as a HttpResource when calling the ‘Hybris as a Service’ Loyalty service. After the response is a success, assign the earned points for that member to the Loyalty Member Earned Points field.
if(ws_result.Code.Contains("200")) // checking for the success
BearerToken = Parser.parse(ws_result.Content,"access_token");
if ( BearerToken == "" )
this.LoyaltyMemberPoints = "empty token";
BearerToken = "Bearer " + BearerToken;
var Loyalty_ScenarioName = "YaaSloyalty";
var Loyalty_ServiceName = "YaaSloyalty";
var Loyalty_HttpResource = this.LoyaltyMemberID;
var Loyalty_ContentType = ""; //not required
var Loyalty_URLParameter : NameAndValue;
var Loyalty_URLParameters : collectionof NameAndValue;
var Loyalty_Body = "";

// get the loyalty points
HeaderParameters.Clear( );
HeaderParameter.Name = "Authorization";
HeaderParameter.Value = BearerToken;

HeaderParameter.Name = "Accept";
HeaderParameter.Value = "application/json";

// Execute webservice call - YaaS Loyalty
var loyalty_result =
Loyalty_ServiceName, HttpMethodGET,Loyalty_HttpResource,Loyalty_URLParameters,
HeaderParameters,Loyalty_ContentType, Loyalty_Body);
var loyaltyPoints;
if (loyalty_result.Code.Contains("200")) // check success
loyaltyPoints = Parser.parse(loyalty_result.Content,"totalEarnedPoints");
if ( loyaltyPoints == "")
this.LoyaltyMemberPoints = "000";
this.LoyaltyMemberPoints = loyaltyPoints;
this.LoyaltyMemberPoints = "error in fetching loyalty points";



Please find the video tutorial link for same:

Hope you find this blog useful and let me know your comments  🙂