Overview

Use the Template service to manage two types of templates in the Customer Journey Manager application:

  • Activity: Use the Activity Template to define an activity to complete a Journey. For example, define a Facebook campaign that captures the number of likes on a page.
  • Stage: Use the Stage Template to define a collection of activities. You can customize an existing stage template by adding more activities to it based on your needs.

Use the Template service to perform these tasks:

  • Create an activity template or a stage template.
  • Use the pre-defined activity templates such as Facebook, Google Adwords, Email, Trigger, and Custom Activity.
  • Use the pre-defined stage templates such as acquire, engage, and retain.
  • Export custom activity and stage templates.
  • Import custom activity and stage templates.

Use a standard REST call to perform all operations related to creating, deleting, viewing, and updating templates.


API Reference

/activities

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

/activities

get

Retrieves a list of activity templates.

Accepted scopes:

  • hybris.template_view – Required to retrieve activity templates
post

Creates an activity template.

Accepted scopes:

  • hybris.template_manage – Required to create an activity template

/activities/{templateId}

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

get

Retrieves an activity template.

Accepted scopes:

  • hybris.template_view – Required to retrieve an activity template
put

Updates an existing activity template.

Accepted scopes:

  • hybris.template_manage – Required to update an activity template
delete

Deletes an existing activity template.

Accepted scopes:

  • hybris.template_delete – Required to delete an activity template

/activities/{templateId}/metricProperties

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

get

Retrieves a list of activity metric properties.

Accepted scopes:

  • hybris.template_view – Required to retrieve activity metric properties

/import

/import

post

Imports templates.

Accepted scopes:

  • hybris.template_manage – Required to import templates

/export

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

/export

get

Export templates

Accepted scopes:

  • hybris.template_manage - Required to export templates

/stages

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

/stages

get

Retrieves a list of stage templates.

Accepted scopes:

  • hybris.template_view – Required to retrieve stage templates
post

Creates a stage template.

Accepted scopes:

  • hybris.template_manage – Required to create a stage template

/stages/{templateId}

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

get

Retrieves a stage template.

Accepted scopes:

  • hybris.template_view – Required to retrieve a stage template
put

Updates a stage template.

Accepted scopes:

  • hybris.template_manage – Required to update a stage template
delete

Deletes a stage template.

Accepted scopes:

  • hybris.template_delete – Required to delete a stage template

/initialLoad

/initialLoad

post

Creates default templates on subscription to Customer Journey Manager package.

Accepted scopes:

  • hybris.template_manage – Required to create default templates


Scopes in Template Service

Scopes prevent unauthorized access to the Template 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 Template service supports these scopes:

ScopeDescription
hybris.template_viewUse this scope to view template.
hybris.template_manageUse this scope to create and modify existing template.
hybris.template_deleteUse this scope to delete existing template.


Perform Simple CRUD Operations in the Template Service

Manage your Customer Journey Manager Activity Templates and Stage Templates using the Template service. To perform the basic create, retrieve, update, and delete (CRUD) operations that the Template service supports, 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+' hybris.template_view hybris.template_manage hybris.template_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 Template service

API.createClient('Template',
'/services/template/v1/api.raml');

Create a template object

Use the POST method to create a template.

The example below illustrates how you create an activity template.

template_obj = Template.activities.post({ 
   "backgroundColor":"#3B5999",
   "category":"Marketing",
   "createdBy":"System",
   "custom":false,
   "description":"Facebook Campaign",
   "iconUrl":"https://api.beta.yaas.io/hybris/media/v2/public/files/57bbe4f5a4b777001db6966e",
   "name":"Facebook",
   "sourceSystemId":"1",
   "templateStatus":"ACTIVE",
   "type":"FB"
}, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Retrieve the template object

Use the GET method to retrieve the activity template you created.

template_obj =  Template.activities.get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )

Update the template object

Use the PUT method to update an existing activity template.

id=template_obj.body[0].id;
Template.activities.templateId(id).put({
   "backgroundColor":"#3B5999",
   "category":"Marketing",
   "createdBy":"System",
   "custom":false,
   "description":"Facebook Campaign created by tutorial",
   "iconUrl":"https://api.beta.yaas.io/hybris/media/v2/public/files/57bbe4f5a4b777001db6966e",
   "name":"Facebook",
   "sourceSystemId":"1",
   "templateStatus":"ACTIVE",
   "type":"FB"
}, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
  },
  query: {
    'partial' : true
  }
})

Retrieve the template object and verify update

Get the activity template to ensure that it was updated.

Template.activities.templateId(id).get(null, {
  headers: {
    'Authorization': 'Bearer ' + access_token,
    'Content-type' : 'application/json'
           }
    }
  )


Glossary

TermDescription
ActivityA distinct task done to achieve a business goal.
Activity TemplateReusable artifact that is used to create an activity in a stage.
StageCollection of activities in a journey, grouped as a logical unit.
Stage TemplateReusable artifact that is used to create a stage in a journey.


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