Loyalty Configuration

Overview

Loyalty Configuration is a core service that you can use to configure loyalty program setup, points-to-currency ratios, and customer advocacy features.

Using this service, you can:

  • Create a loyalty program.
  • Add tiers for a loyalty program, for example, Bronze, Silver, and Gold.
  • Select a commerce platform: SAP Hybris Commerce Suite or SAP Hybris Commerce-as-a-Service.
  • Show or hide reward information.
  • Show a cash balance instead of points.
  • Configure a points-to-currency ratio.
  • Configure customer advocacy features.


Error Types

For more information about error codes, see the detailed error description for each API operation in the API Reference. You can also check the standard error codes in the API best practices.


Scopes

Scopes are strings that you can use to specify the type of access you need to resources and operations in the Loyalty Configuration service.

You must provide a proper scope that allows users to perform certain operations. Grant the scopes in an access token from the OAuth2 service. For more information about the authorization and authentication used in SAP Hybris services, and also about the scopes in general, see: Authorization Scopes

The table shows the scopes that the Loyalty Configuration service supports.

ScopeDescription
sap.loyconfig_manageUse this scope to create and modify existing configurations.


Perform Simple CRUD Operations on Loyalty Configuration Service

Introduction

Manage your Loyalty service configurations using the Loyalty Configuration service. The Loyalty Configuration service supports the create, retrieve, update, and delete operations. To perform the basic operations supported by the Configuration service, you must have proper authorization, which requires that the header carries the correct access token. The examples in this tutorial lead you through those operations, showing what you need to provide to the methods, and the responses you receive in return.

clientId = clientIdPlaceholder;
clientSecret = clientSecretPlaceholder;
tenant = projectIdPlaceholder;
client = appIdPlaceholder;
scopesRequired = 'hybris.tenant='+tenant+' sap.loyconfig_view sap.loyconfig_manage sap.loyconfig_delete';
access_token = tokenPlaceholder;

Get an access token

To perform any operation, you need an access token. To obtain an access token, create an API Client for the OAuth2 service:

API.createClient('oAuth2Service',
'/services/oauth2/v1/api.raml');

Now, get the token:

AccessToken = oAuth2Service.token.post({
  'client_id' : clientId,
  'client_secret': clientSecret,
  'grant_type' : 'client_credentials',
  'token_type': 'Bearer',
  'scope': scopesRequired
});
access_token = AccessToken.body.access_token;

Create an API client for the Loyalty Configuration service

API.createClient('ConfigurationService',
'/services/loyaltyconfiguration/v1/api.raml');

Create a Loyalty program configuration object

You can create only one Loyalty program per tenant.

configuration_obj = ConfigurationService.programConfigurations.post({
   "loyaltyProgramName":"Sample Program",
   "programId":"DummyId",
   "configData":[
      {
         "name":"showReward",
         "value":"true"
      },
      {
         "name":"showCashBal",
         "value":"false"
      },
      {
         "name":"cashToReward",
         "value":"1"
      }
   ],
   "conversionRatio":[
      {
         "conversionType":"EARNING",
         "currencyValue":"1",
         "currencySymbol":"USD",
         "pointValue":"1"
      },
      {
         "conversionType":"EARNING",
         "currencyValue":"1",
         "currencySymbol":"EUR",
         "pointValue":"1"
      },
      {
         "conversionType":"REDEEMING",
         "currencyValue":"1",
         "currencySymbol":"USD",
         "pointValue":"100"
      }
   ],
   "urlMapping":[
      {
         "name":"Membership",
         "value":"url1"
      },
      {
         "name":"Revenue",
         "value":"url2"
      },
      {
         "name":"Points",
         "value":"url3"
      }
   ]
}, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Retrieve the Loyalty program configuration object

config_obj =  ConfigurationService.programConfigurations.get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Update the program configuration object

Perform a partial update on the object.

loyaltyProgramId=config_obj.body[0].programId;
loyaltyConfigurationId=config_obj.body[0].configurationId;
ConfigurationService.programConfigurations.programId(loyaltyProgramId).put({
   "programId":loyaltyProgramId,
   "configurationId":loyaltyConfigurationId,
   "programTiers":[
      {
         "name":"Gold",
         "tierOrder":"5",
         "tierId":"",
         "programId":"",
         "tierMode":"C"
      }
   ]
}, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
  },
  query: {
    'partial' : true
  }
})

Retrieve the program configuration object and verify update

Get the program configuration object to make sure that it was updated.

ConfigurationService.programConfigurations.programId(loyaltyProgramId).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )


  • Send feedback

    If you find any information that is unclear or incorrect, please let us know so that we can improve the Dev Portal content.

  • Get Help

    Use our private help channel. Receive updates over email and contact our specialists directly.

  • hybris Experts

    If you need more information about this topic, visit hybris Experts to post your own question and interact with our community and experts.