Overview

Use the Loyalty Email service to create and upload templates for notification emails that you can send by making a simple REST call. You can create and manage email templates for any notification purpose, including:

  • Successful registration
  • Order confirmation
  • Account expiration
  • Referral emails
  • Tier upgrades
  • Offers

The Loyalty Email service can send an email to individual recipients when a corresponding action triggers the service. For example, the system can:

  • send a registration notification email when a customer registers for a loyalty program
  • email an order confirmation, after a customer submits an order, that lists the purchased items
  • send a referral email to a customer's friends when the customer registers for a loyalty program
  • send a notification when a customer's account upgrades from the bronze tier to silver
  • notify the customer when an account expires
  • email product offers to a customer


API Reference

/content

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

/content

get

Gets all Content from Document repository

Accepted scopes:

  • 'sap.loyemail_view' - Required to get all Content
post

Creates a new Content in document repository based on contentType EMAIL and EMAIL_TEMPLATE

Accepted scopes:

  • 'sap.loyemail_manage' - Required to post Content

/content/aggr

get

Gets average, sum and count aggregation for content

Accepted scopes:

  • 'sap.loyemail_view' - Required to gets average, sum and count aggregation for content

/content/{contentId}

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

get

Gets a specific content based on contentId provided.

Accepted scopes:

  • 'sap.loyemail_view' - Required to view Content by ID
put

Updates the specific content in Document Repository based on contentId and contentType

Accepted scopes:

  • 'sap.loyadvocacy_manage' - Required to post Content
delete

Deletes a specific content based on contentId provided

Accepted scopes:

  • 'sap.loyemail_delete' - Required to delete Content

/send

This resourceType defines the POST method and their responses for a collection resource.

/send

post

Sends email to user. If it fails, it will create a PubSub topic sendEmailCreationFailed for fault tolerance

Accepted scopes:

  • 'sap.loyemail_manage' - Required to post Content

/initialLoad

This resourceType defines the POST method and their responses for a collection resource.

/initialLoad

post

Upload standard system Email Template for a tenant. Use this as a fall back option only when automatic creation of default system Email Template fails for the tenant.

Accepted scopes:

  • 'sap.loyemail_manage' - Required to post initailLoad

/messagelogs

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

/messagelogs

get

Gets all email message log files when an email is sent

post

Creates a new email message log file when an email is sent

/messagelogs/{messagelogId}

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

get

Gets a specific email message log file based on the id provided

put

Updates a specific email message log file based on the id provided

delete

Deletes a specific email message log file based on the id provided

/secureMediaUri/{mediaId}

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

/secureMediaUri/{mediaId}

get

Do Not Use Accepted scopes:

  • 'sap.loycard_view' - Required to get secureMediaUri
put

Updates a single secureMediaUri entity.

delete

Deletes a single secureMediaUri entity.

/migration

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

/migration

get

Get Content

Accepted scopes:

  • 'sap.loyemail_view' - Required to get all Content

/loyEmailConfiguration

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

/loyEmailConfiguration

get

Gets all Loyalty Email Configuration

Accepted scopes:

  • 'sap.loyemail_view' - Required to get all Loyalty Email Configuration
post

Creates a new Loyalty Email Configuration

Accepted scopes:

  • 'sap.loyemail_manage' - Required to post Loyalty Email Configuration

/loyEmailConfiguration/{emailConfigId}

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

get

Gets a specific Loyalty Email Configuration based on emailConfigId provided.

Accepted scopes:

  • 'sap.loyemail_view' - Required to view Content by ID
put

Updates the specific Loyalty Email Configuration in Document Repository based on emailConfigId

delete

Deletes a specific Loyalty Email Configuration based on emailConfigId provided


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 that you can use to specify the type of access you need to resources and operations in the Loyalty Email 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 Email service supports. It also names the tutorials that contain examples using the proper scopes.

ScopeDescription
sap.loyemail_viewUse this scope to view all emails and email templates for the Loyalty Email service.
sap.loyemail_manageUse this scope to create and update emails and email templates.
sap.loyemail_deleteUse this scope to delete emails and email templates.


Perform Simple CRUD Operations on Content Object

Introduction

You can manage emails and email templates using the Loyalty Email service. This tutorial describes how to manage emails and templates using the basic create, read, update, and delete operations.

assert = chai.assert;
clientId = clientIdPlaceholder;
clientSecret = clientSecretPlaceholder;
tenant = projectIdPlaceholder;
client = appIdPlaceholder;
scopesRequired = 'hybris.tenant='+tenant+' sap.loyemail_view sap.loyemail_manage sap.loyemail_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 Loyalty Email service

API.createClient('contentService',
'/services/loyaltyemail/v1/api.raml');

Create an email template object

content_postResponse = contentService.content.post({
   "contentItem":{
      "contentType":"EMAIL_TEMPLATE",
      "description":"TurorialCheckEmail",
      "contentStatus":"ACTIVE",
      "contentId":"",
      "createdBy":null,
      "updatedBy":null,
      "name":"TurorialCheckEmail",
      "isUsed":false,
      "refContentId":""
   },
   "contentDetail":{
      "file":{
         "en":"\n\n\t<div align=\"center\" style=\"border: none;\">\n\ttest template \n\t</div>\t\t\n\n"
      }
   }
}, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Get the email template content ID

locationRef = content_postResponse.headers.location.toString();
contentId = locationRef.substring(locationRef.lastIndexOf('/')+1,locationRef.length);

Retrieve the email template object


getByContentIdRes = contentService.content.contentId(contentId).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Update the email template object

putResponse = contentService.content.contentId(contentId).put({
   "contentItem":{
      "contentType":"EMAIL_TEMPLATE",
      "description":"TurorialCheck",
      "contentStatus":"ACTIVE",
      "contentId":"",
      "name":"TurorialCheck",
      "isUsed":false,
      "refContentId":""
   },
   "contentDetail":{
      "file":{
         "en":"\n\n\t<div align=\"center\" style=\"border: none;\">\n\ttest template \n\t</div>\t\t\n\n"
      }
   }
}
, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
  }
})

Create an email object

contentEmail_Response = contentService.content.post({
   "contentItem":{
      "contentStatus":"ACTIVE",
      "contentType":"EMAIL",
      "name":"apinote1",
      "dateValidFrom":"",
      "dateValidTo":"",
      "createdBy":"null",
      "updatedBy":"null",
      "isUsed":false,
      "refContentId":contentId
   },
   "contentDetail":{
      "emailItem":[
         {
            "name":"apinote1",
            "definableAttributes":[

            ]
         }
      ],
      "body":{
         "en":"\n\n&#9;<div align=\"center\" style=\"border: none;\">\n&#9;test template \n&#9;</div>&#9;&#9;\n\n"
      },
      "subject":{
         "en":"apinote1"
      }
   }
}, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Get an email ID

locationRefEmail = contentEmail_Response.headers.location.toString();
emailContentId = locationRefEmail.substring(locationRefEmail.lastIndexOf('/')+1,locationRefEmail.length);

Retrieve the email object

getByContentIdEmailRes = contentService.content.contentId(emailContentId).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Get an email name from the email response object

emailName = getByContentIdEmailRes.body.contentItem.name

Send an email to a recipient

sendEmail_Response = contentService.send.post({  
   "toAddress":"xyz@gmail.com",
   "fromAddress":"noreply@yaas.io",
   "templateCode":emailName,
   "templateOwner":"dummy.dummy",
   "locale":"en"
}, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Delete an email object


deleteEmailResponse = contentService.content.contentId(emailContentId).delete(null, {
  headers: {
   'Authorization': 'Bearer ' + access_token,
  }
})

  assert.equal(deleteEmailResponse.status, 204);

Delete an email template object

deleteEmailTemplateResponse = contentService.content.contentId(contentId).delete(null, {
  headers: {
   'Authorization': 'Bearer ' + access_token,
  }
})

  assert.equal(deleteEmailTemplateResponse.status, 204);

Get an email template by ID after deleting

getETbyIdRes = contentService.content.contentId(contentId).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

    assert.equal(getETbyIdRes.status, 404);

Get an email by ID after deleting

getEmailbyIdRes = contentService.content.contentId(emailContentId).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

    assert.equal(getEmailbyIdRes.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.