personalizationwebservices Extension

The personalizationwebservices extension contains the personalization api which allows the introduction of changes to the customer experience data model using the rest calls. It contains the functionality for core personalization, with the possibility to extend this functionality with some other extensions.

Extension Structure

As you can see in the figure below, the personalizationwebservices extension depends on the personalizationservices extension (for the domain) and the webservicescommons (for web functionality). Because the personalizationservices extension provides only basic functionality for customer experience without defining any particular actions, the personalizationwebservices extension also can’t provide the functionality for specific actions. However, the actions are supported by additional extensions (such as personalizationcms extension or personalizationpromotions extension) which in turn depend on personalizationservices. Therefore, the personalizationcmsweb extension was created to extend the personalization API with functionality related to CMS (for example creating a CxCmsAction).

The personalizationsearchweb extension extends the personalizationwebservices extension with information required to use the personalized search functionality through the provided web services. For details, see Personalization Search Module.

Authorization and Authentication

To call the API, you have to be authorized and authenticated and you need a proper token to use the web services. The API provided by personalizationwebservices is secured by OAuth 2.0. To get the access token, you need an OAuth client defined in the system and a user with proper rights. SAP Commerce Cloud does not provide sample OAuth clients, so you have to define your own. For instructions, see Configuring OAuth Clients.

Different permissions are required based on which endpoint you want to call. For the catalog-aware endpoints the requirements are as follows:
  • To execute a write request (POST, DELETE, UPDATE, PATCH) you need the write access to the catalog/catalogVersion on top of being included in the cxmanagergroup or the admingroup.
  • To execute a read request (GET), you just need to have read access to a given catalog/catalogVersion, so you need to belong to cxreadonlygroup (which gives you the right to only view the combined view in personalization mode), the cxmanagergroup or the admingroup.

For non-catalog-aware endpoints such as segments/, customersegmentations/ or queries/, you just need to be in the cxmanagergroup or admingroup.

The access to the following endpoints is denied by default, in order to improve and maintain security:
  • v1/customersegmentations
  • POST /v1/segments
  • PUT /v1/segments/ {segmentCode}
  • DELETE /v1/segments/{segmentCode}

Using these endpoints requires changes in the security configuration. If you have insufficient rights, a 403 will be returned by the webservices.

This security check is enforced by spring security configuration located in /personalizationwebservices/web/webroot/WEB-INF/config/security-spring.xml. You can overwrite the security-spring.xml file by using the personalizationwebservices.security.config property pointing to a different spring security configuration file.

Base Site Support

The baseSiteHeaderFilter was added after the restSessionFilter and before the catalogVersionFilter.

For every request to personalizationwebservices, the baseSiteHeaderFilter reads the header containing basesite and if the value is present, it sets the value as a current base site in the session.

Overriding spring-security.xml File

The personalizationwebservices extension allows overwriting its default spring-security.xml file with a custom one. The file should be placed in the resources folder of your extension. To specify the file path, you should use personalizationwebservices.security.spring property as presented below:
personalizationwebservices.security.spring=classpath:/myextension/custom-spring-security.xml

Cross-Origin Resource Sharing

The CORS mechanism defines a way for a browser and a server to decide which cross-origin requests to allow for restricted resources. Personalization Web Services use standard SAP Commerce sharing mechanism, which allows to configure CORS attributes as project properties or define it in Backoffice application. Configure sample values in the personalizationwebservices/project.properties file:

corsfilter.personalizationwebservices.allowedOrigins=http://localhost:4200 https://localhost:4200 
corsfilter.personalizationwebservices.allowedMethods=GET
corsfilter.personalizationwebservices.allowedHeaders=origin content-type accept authorization

You can override this configuration using Backoffice settings. To do so, select Start of the navigation pathSystem Next navigation step CORS Filter Next navigation step CorsConfigurationPropertyEnd of the navigation path.

For more details, see: Cross-Origin Resource Sharing Support.

personalizationwebservices Endpoints

List of personalizationwebservices Endpoints

URL Method Description Catalog aware Supports Fields Parameter Paginated Remarks
/customizations GET returns all customizations yes yes yes for supported query parameters see the Parameters supported by the /customizations endpoint section below.
/customizations POST creates customization yes      
/customizations/{customizationID} GET returns customization with given id yes yes    
/customizations/{customizationID} PUT updates customization with given id yes      
/customizations/{customizationID} DELETE deletes customization with given id (also deletes all variations and actions related to this customization) yes      
/customizations/{customizationID}/variations GET returns all variations for this customization yes yes    
/customizations/{customizationID}/variations POST creates variation within this customization yes      
/customizations/{customizationID}/variations/{variationId} GET returns variation with given id from this customization yes yes    
/customizations/{customizationID}/variations/{variationId} PUT updates variation with given id from this customization yes      
/customizations/{customizationID}/variations/{variationId} DELETE deletes variation with given id (also deletes all actions related to this variation) yes      
/customizations/{customizationID}/variations/{variationId}/actions GET returns all actions within this variation yes yes    
/customizations/{customizationID}/variations/{variationId}/actions POST creates action within this variation yes      
/customizations/{customizationID}/variations/{variationId}/actions/{actionId} GET returns action with given id yes yes    
/customizations/{customizationID}/variations/{variationId}/actions/{actionId} PUT updates action with given id yes      
/customizations/{customizationID}/variations/{variationId}/actions/{actionId} DELETE deletes action with given id yes      
/actions GET gets actions from multiple customizations/variations yes

yes

yes currently, the type parameter is required and the only supported value is CXCMSACTION
/customizations/{customizationID}/variations/{variationId}/triggers GET returns all segment triggers for given variation yes yes    
/customizations/{customizationID}/variations/{variationId}/triggers POST creates new segment trigger for given variation yes     currently only one from the following: segmentTrigger/expressionTrigger/defaultTrigger can be related to a given variation
/customizations/{customizationID}/variations/{variationId}/triggers/{triggerId} GET gets segment trigger with given id yes yes    
/customizations/{customizationID}/variations/{variationId}/triggers/{triggerId} PUT updates segment trigger with given id yes      
/customizations/{customizationID}/variations/{variationId}/triggers/{triggerId} DELETE removes segment trigger with given id yes      
/segments GET returns all segments no yes yes supported query parameters: code
/segments POST creates segment no      
/segments/{segmentId} GET returns segment with given id no yes    
/segments/{segmentId} PUT updates segment no      
/segments/{segmentId} DELETE removes segment no      
/customersegmentations GET returns relations between customer and segment no yes yes at least one query parameter is required: customerId - uid of customer segmentId - code of segment
/customersegmentations POST creates relation between customer and segment no      
/customersegmentations/{customersegmentationId} GET returns relation with given id   yes    
/customersegmentations/{customersegmentationId} PUT updates relation with given id no      
/customersegmentations/{customersegmentationId} DELETE removes relation with given id no      
/query/{queryId} POST executes query with given id (?)     this is very generic endpoint for executing extension specific queries (e.g. cms)

Parameters Supported by the /customizations Endpoint

The following parameters are supported by the /customizations endpoint returning all customizations.
  • Required parameters means that the parameters necessary for the query parameter to work properly.
  • Works with parameters means that the query parameter can work together only with the listed ones. "-" means that the query parameter cannot be used together with other parameters.
  • Required extension means that the extension that needs to be in use for the parameter to work.
Query parameter Description Values Required parameters Works with parameters Required extension
code filters response by code of the customization string - - personalizationservices
statuses filters response by status of the customization, a comma-seperated list ENABLED, DISABLED, DELETED - name, pageId personalizationservices
name filters the response by the name of customization string statuses - personalizationservices
catalogs filters response by catalog of the customization, CURRENT by default. PARENTS display customizations from parent catalogs of specified catalog. ALL displays customizations from CURRENT and PARENTS. PARENTS and ALL have meaning only in multi-country setup. CURRENT, PARENTS, ALL - All personalizationcms
pageId filters response by customization that have actions affecting the page string statuses pageCatalogId, negatePageId personalizationcms
pageCatalogId defines catalog for page defined by pageId. string pageId - personalizationcms
negatePageId if set to true will search for customizations not affecting the page true, false pageId - personalizationcms

Catalog Aware Endpoints

The catalog aware functionality is handled by de.hybris.platform.webservicescommons.filter.CatalogVersionFilter declared in /personalizationwebservices/web/webroot/WEB-INF/personalizationwebservices-web-spring.xml file. For details on the CatalogVersionFilter see: Common Filters and Controllers.

Fields Parameter

All GET methods support fields query parameter which allows defining which fields of the requested object should be included in the response. The format of this parameter is described in more details in: Fields Configuration Format. The fields are supported by aspect fieldsetAspect declared in the /personalizationwebservices/web/webroot/WEB-INF/springmvc-servlet.xml file.
...   
    <aop:aspectj-autoproxy />
     
    <bean id="aopFieldsetConverter" class="de.hybris.platform.webservicescommons.mapping.aop.FieldsFilter" autowire="constructor">
        <property name="disableFullMapping" value="true" />
    </bean>
     
    <aop:config>
        <aop:aspect id="fieldsetAspect" ref="aopFieldsetConverter">
            <aop:pointcut expression="execution(public * de.hybris.platform.personalizationwebservices.controllers.*.get*(..))" id="fieldsetPointcut" />
            <aop:around method="filterFields" pointcut-ref="fieldsetPointcut"/>
        </aop:aspect>
    </aop:config>
...

Response Pagination

If the endpoint supports pagination, it accepts two additional parameters in the query:
  • pageSize: number of items on the returned page

  • currentPage: number of the current page to return (starting from 0)

Actions Endpoint

Actions can be accessed using two different endpoints:
  • /customizations/{customizationID}/variations/{variationId}/actions: dedicated for manipulating actions (create / update / delete). Queries are restricted to actions in a given customization/variation and supported query parameters are limited.
  • /actions: this endpoint supports the GET operation only, and returns a list of actions from multiple customizations or variations.

Action endpoints use dynamic response type mechanism to return data from specific action subclass. For details, see Dynamic Response Types in Web Services. For details on extending the action endpoint, see Create a Personalization Action, for details on extending action queries, see Data Filtering in personalizationservices Extension.

Trigger Endpoint

The Trigger endpoint uses the dynamic response type mechanism to return data from a specific abstractTrigger subclass. For details on the mechanism, see also: Dynamic Response Types in Web Services.

By default the system provides the following trigger types:
  • segmentTrigger, providing a simple way of triggering variation using a list of segments joined by logical operators AND or OR. A sample body in JSON format looks as follows:
    {
      "type": "segmentTriggerData",
      "code": "trigger1",
      "groupBy": "AND",
      "segments": [
        {
          "code": "Men"
        },
        {
          "code": "VIPBronze"
        }
      ]
    }
  • expressionTrigger, providing support for complex logical expressions containing AND / OR / NOT operations on segments. A sample body in JSON format looks as follows:
    {
      "type": "expressionTriggerData",
      "code":"exTrigger1",
      "expression": {"type":"groupExpressionData", "operator":"OR", "elements":[
          {"type":"segmentExpressionData", "code":"Men"},
          {"type":"groupExpressionData", "operator":"AND", "elements":[
              {"type":"segmentExpressionData", "code":"Women"},
              {"type":"negationExpressionData", "element":
                  {"type":"segmentExpressionData", "code":"HatsFan"}
              }
          ]}
      ]}
    }
For more information on triggers, see: Variation Triggers.

Query Endpoint

A query endpoint is a generic endpoint, which executes the logic from a bean with given ID. The bean implements the de.hybris.platform.personalizationwebservices.queries.RestQueryExecutor interface in order to be visible in the Query endpoint. Any extension may declare such a bean to extend the functionality available through this endpoint. The main purpose for adding such beans is to enable access to functionality specific for a given subtype of CxAbstractAction through web services.

For example, the CxCmsAction defines the CmsComponent, which should be displayed by the CxCmsContainer. To learn which CMS components are affected by a given variation, you need logic aware of CxCmsContainer. Such custom logic is specific for the personalizationcmsweb extension and cannot be placed in personalizationwebservices.

When implementing your own RestQuery, you need the following methods from the RestQueryExecutorInterface:
  • Object execute(Map<String, String> params): this is where the logic of your query goes. For example, execute a flexissearch, update and save the data model.
  • List<CatalogVersionWsDTO> getCatalogsForWriteAccess(final Map<String, String> params): this is where you declare which catalogs will be used to write data. This is important if you want permissions check for your query.
  • List<CatalogVersionWsDTO> getCatalogsForReadAccess(final Map<String, String> params): this where you declare which catalogs will be used to read data from. This is important if you want permissions check for your query.

The query endpoint accepts a single parameter of de.hybris.platform.personalizationwebservices.data.QueryParamsWsDTO type, which consists of a single string - string map. The queryId is the name of bean which should be executed with given parameters. The bean can do anything it wants and should return an object representing rest response. It may be anything from a simple WsDTO object up to a ResponseEntity.

For example, in the cxcmsweb extension you may define the cxcmscomponentsfromvariations bean.
<bean id="cxcmscomponentsfromvariations" class="de.hybris.platform.personalizationcmsweb.queries.CmsComponentsQueryExecutor" parent="abstractFlexibleSearchRestQuery" />

de.hybris.platform.personalizationcmsweb.queries.CmsComponentsQueryExecutor implements de.hybris.platform.personalizationwebservices.queries.RestQueryExecutor and executes flexible search to extract information about the components affected by given variations. Such data would be unavailable in any other way trough personalization API. For details see the Queries section in personalizationcmsweb Extension.

personalizationwebservices API Reference

For the API Reference for the personalizationwebservices extension, see API Documentation and YAML Files.