Alokai

setCustomerContext

Creates the shopper's context based on shopperJWT, if one doesn't exits already, otherwise updates it.

Calls the getShopperContext and the createShopperContext or the updateShopperContext endpoints exposed by SCAPI depending on the state of the current customer's shopper context.

When updating: - If the shopper context exists, it's updated with the patch body. - If a custom qualifier/assignment qualifer or an effectiveDateTime or a sourceCode or a customerGroupIds is already present in the existing shopper context, its value is replaced by the corresponding value from the patch body. - If a custom qualifers' or a assignment qualifiers' value is set to null, it's deleted from existing shopper context. - If effectiveDateTime or sourceCode value is set to an empty string (""), it's deleted from existing shopper context. - If effectiveDateTime or sourceCode value is set to null, it's ignored. - If an effectiveDateTime or sourceCode or custom/assignment qualifiiers' value is new, it's added to the existing Shopper context. - If customerGroupIds is set to empty array [] the existing value in shopper context is deleted.

Signature

export declare function setCustomerContext(
	props: CustomerContextModifyParams
): Promise<CustomerContext>;

Parameters

NameRequiredTypeDescription
propsRequiredCustomerContextModifyParamsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.

Returns

Returns a representation of a Customer Context.

Referenced Types

  • CustomerContextModifyParams
  • CustomerContext

Examples

Creating or updating a customer context.

import { sdk } from '~/sdk.config.ts';

const customer = await sdk.commerce.setCustomerContext({
  "effectiveDateTime": "2020-12-20T00:00:00Z",
  "sourceCode": "wii1-98",
  "customQualifiers": {
    "deviceType": "mobile",
    "ipAddress": "189.0.0.0",
    "operatingSystem": "Android"
  },
  "assignmentQualifiers": {
    "store": "boston"
  },
  "customerGroupIds": [
    "BigSpenders",
    "MobileUsers"
  ]
});

On this page