Loyalty Advocacy

Overview

The Loyalty Advocacy service provides the ability for consumers to submit ratings and review comments for products in a storefront. In the storefront, consumers can view the average user rating, all ratings and review comments, and the total number of ratings for the selected product.


API Reference

/ratingReviewMashup

This resourceType defines the POST, PUT methods and their responses for a collection resource.

/ratingReviewMashup

post

To provide Rating and Review for a product.

Details:

  • Member activities gets created for Rating and Review
  • If rules are defined to award loyalty points for providing the Rating and Review, user will be awarded with points.

/ratingReviews

This resourceType defines the GET, POST, DELETE methods and their responses for a collection resource.

/ratingReviews

get

Gets all Product Ratings and Reviews. Pass Product SKU as query parameter to fetch Rating and Review for a particular Product

post

DO NOT USE. Creates a Rating and Review for Product. Use /ratingReviewMashup to provide Rating and Review

Accepted scopes:

  • 'sap.loyadvocacy_manage' - Required to post Rating and Review

/ratingReviews/aggr

get

Gets Average, Sum and Count of Rating and Review. Pass product SKU as a part query parameters to fetch average for a given product

/ratingReviews/{ratingReviewId}

This resource type defines the GET, PUT, DELETE methods and their responses for a single element resource.

get

Gets a specific Product Rating and Review based on the ratingId provided

put

Updates a specific Product Rating and Review based on the ratingId provided

Accepted scopes:

  • 'sap.loyadvocacy_manage' - Required to update Rating and Review
delete

Deletes a specific Product Rating and Review based on the ratingId provided

Accepted scopes:

  • 'sap.loyadvocacy_delete' - Required to post Rating and Review

/ratingReviews/{productId}/ratingCount

This resource type defines the GET, PUT, DELETE methods and their responses for a single element resource.

get

Gets Individual rating value count for each Rating.

put

Updates a single ratingCount entity.

delete

Deletes a single ratingCount entity.

/sendReferral

This resourceType defines the POST, PUT methods and their responses for a collection resource.

/sendReferral

post

Sends out referral emails to non-registered loyalty members. Use this end point to invite friends to join the loyalty program. If corresponding rules are defined, the referral would earn loyalty points.

Details:

  • To send invite to multiple friends, separate the email id's by comma(,)
  • Enable Advocacy(referral) feature in the configuration
  • Ensure referral email template exists in the system and is configured in the configuration


Error Types

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


Scopes

Scopes are strings that let you specify exactly what type of access you need to resources and operations in the Loyalty Advocacy service.

You must provide a proper scope that enables users to perform certain operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, and also about the scopes in general, see: Authorization Scopes

The table presents all the scopes supported by the Loyalty advocacy service.

ScopeDescription
sap.loyadvocacy_viewUse this scope to retreive existing ratings and reviews.
sap.loyadvocacy_manageUse this scope to create or modify existing rating and review.
sap.loyadvocacy_deleteUse this scope to delete an existing rating and review.


Create and manage a rating and review mashup service

Loyalty Advocacy Service allows the user to rate or review any products available in the storefront of Loyalty Program. The loyalty member earns points on rating and review activities.

Introduction

With the Loyalty Advocacy service, you can manage ratings and reviews. This tutorial shows how to create a rating and review mashup service and how to manage ratings and reviews using the create, read, update, and delete (CRUD) operations.

Example

assert = chai.assert;
clientId = clientIdPlaceholder;
clientSecret = clientSecretPlaceholder;
tenant = projectIdPlaceholder;
client = appIdPlaceholder;
scopesRequired = 'hybris.tenant='+tenant+' sap.loyadvocacy_view sap.loyadvocacy_manage sap.loyadvocacy_delete';
token = tokenPlaceholder;

Get an access token

To perform CRUD operations, you must have proper authorization, which requires a valid access token in the request header. 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 Advocacy service

API.createClient('AdvocacyService',
'/services/loyaltyadvocacy/v1/api.raml');

Create a rating review mashup object

The code in this example shows default values from a test project. When you create a rating review mashup for your project, replace the payload in the example with the proper values for the sku, the customerId, and other fields as required for use in your project.

 mashup_obj = AdvocacyService.ratingReviewMashup.post({
'ratingId':ratingId,
'sku':'57318a72bf5841001df44757',
'rating':4,
'reviewerName':'SYSTEM',
'customerId':'C4173571841',
'reviewTitle':'Monitor',
'reviewComment':'Clarity is good',
'reviewStatus':'PUBLISHED'
}, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

 assert.equal(mashup_obj.status, 201);
path = mashup_obj.headers.location.split('/').reverse();
id = path[0];

Retrieve the rating review mashup object

 getAdvocacyResponse = AdvocacyService.ratingReviews.ratingReviewId(id).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

  assert.equal(getAdvocacyResponse.status, 200);

Update the rating review object

Perform a partial update on the object using this code.

 putAdvocacyResponse = AdvocacyService.ratingReviews.ratingReviewId(id).put({
'ratingId':id,
'sku':'57318a72bf5841001df44757',
'rating':4,
'reviewerName':'SYSTEM',
'customerId':'C4173571841',
'reviewTitle':'Good',
'reviewComment':'Clarity is awesome',
'reviewStatus':'PUBLISHED'
},  {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
  },
  query: {
    'partial' : true
  }
})

 assert.equal(putAdvocacyResponse.status, 200);

Retrieve the rating review object and verify the update

Verify that the object you updated in the previous step appears as expected.

 getAdvocacyResponse = AdvocacyService.ratingReviews.ratingReviewId(id).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )
  assert.equal(getAdvocacyResponse.status, 200);

Delete the rating review object

 deleteResponse = AdvocacyService.ratingReviews.ratingReviewId(id).delete(null, {
  headers: {
   'Authorization': 'Bearer ' + access_token,
  }
})

 assert.equal(deleteResponse.status, 204);

Retrieve the deleted rating review object and verify the delete

Verify that the object is deleted using the following code as an example.

 advocacyResponse = AdvocacyService.ratingReviews.ratingReviewId(id).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

  assert.equal(advocacyResponse.status, 404);


  • 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.