Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ShopperContexts<ConfigParameters>

*# API Overview

With the Shopper Context API, you can set any context information as a key/value pair and use it to retrieve personalized promotions, payment methods, and shipping methods. The context information that is set is evaluated against the customer group definitions to determine a customer group (shopper segment), and is then used to activate the experiences that are associated with a particular segment, such as promotions.

You can also get personalized API responses triggered by shopper context from the Open Commerce API (OCAPI). Support for both the B2C Commerce API and OCAPI allows shopper context to be used in hybrid deployments.

Warning* Access tokens with a scope that includes the Shopper Context API are powerful. They can activate specific promotions and can be used to see how a storefront would be displayed in the future. Don't share them with untrusted clients like web browsers or client apps.

Make Shopper Context calls with a private client and only set shopper context through a secure backend channel. To avoid misuse, do not make direct calls through a browser or similar client in which data can be viewed.

As part of this, when creating a SLAS public client for a tenant, if you attempt to add the Shopper Context API scope, a warning message is displayed to ensure you are aware of the pitfalls of doing so.

Note*:

Shopper context is valid for 1 day for guest shoppers and 7 days for registered shoppers. To extend the context set, create a new context. As a best practice, refresh your contexts periodically to ensure that the right personalized experience is rendered for your shoppers.

Authentication & Authorization

The Shopper Context API requires a shopper access token from the Shopper Login and API Access Service (SLAS).

For details on how to request a shopper access token from SLAS, see the guest user flows for public clients and private clients in the SLAS guides.

Add sfcc.shopper-context.rw to the scopes configuration for the SLAS API client.

For more information, see Authorization for Shopper APIs in the Get Started guides.

Warning*: As with all APIs, never store access tokens in the browser because this creates a security vulnerability.

Use Cases

For detailed usage information, see the Shopper Context guides.*

Simple example:

  import { ShopperContext } from "commerce-sdk-isomorphic";

  const clientConfig = {
    parameters: {
      clientId: "XXXXXX",
      organizationId: "XXXX",
      shortCode: "XXX",
      siteId: "XX"
    }
  };
  const shopperContextClient = new ShopperContext(clientConfig);
API Version: 0.0.33
Last Updated:

Type parameters

Hierarchy

  • ShopperContexts

Index

Constructors

constructor

Properties

clientConfig

clientConfig: ClientConfig<ConfigParameters> & { baseUri: string }

Static Readonly defaultBaseUri

defaultBaseUri: "https://{shortCode}.api.commercecloud.salesforce.com/shopper/shopper-context/v1" = currentBaseUri

Static Readonly paramKeys

paramKeys: { createShopperContext: ["usid", "organizationId", "siteId", "evaluateContextWithClientIp"]; createShopperContextRequired: ["usid", "organizationId", "siteId"]; deleteShopperContext: ["usid", "organizationId", "siteId"]; deleteShopperContextRequired: ["usid", "organizationId", "siteId"]; getShopperContext: ["usid", "organizationId", "siteId"]; getShopperContextRequired: ["usid", "organizationId", "siteId"]; updateShopperContext: ["usid", "organizationId", "siteId", "evaluateContextWithClientIp"]; updateShopperContextRequired: ["usid", "organizationId", "siteId"] } = {createShopperContext: ['usid','organizationId','siteId','evaluateContextWithClientIp',],createShopperContextRequired: ['usid','organizationId','siteId',],deleteShopperContext: ['usid','organizationId','siteId',],deleteShopperContextRequired: ['usid','organizationId','siteId',],getShopperContext: ['usid','organizationId','siteId',],getShopperContextRequired: ['usid','organizationId','siteId',],updateShopperContext: ['usid','organizationId','siteId','evaluateContextWithClientIp',],updateShopperContextRequired: ['usid','organizationId','siteId',],} as const

Type declaration

  • createShopperContext: ["usid", "organizationId", "siteId", "evaluateContextWithClientIp"]
  • createShopperContextRequired: ["usid", "organizationId", "siteId"]
  • deleteShopperContext: ["usid", "organizationId", "siteId"]
  • deleteShopperContextRequired: ["usid", "organizationId", "siteId"]
  • getShopperContext: ["usid", "organizationId", "siteId"]
  • getShopperContextRequired: ["usid", "organizationId", "siteId"]
  • updateShopperContext: ["usid", "organizationId", "siteId", "evaluateContextWithClientIp"]
  • updateShopperContextRequired: ["usid", "organizationId", "siteId"]

Methods

createShopperContext

  • If you would like to get a raw Response object use the other createShopperContext function.

    Parameters

    Returns Promise<void>

    A promise of type void.

  • Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : void>

    A promise of type Response if rawResponse is true, a promise of type void otherwise.

deleteShopperContext

  • Get a shopper's context based on the shopperJWT.

    If you would like to get a raw Response object use the other deleteShopperContext function.

    Parameters

    Returns Promise<void>

    A promise of type void.

  • Get a shopper's context based on the shopperJWT.

    Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : void>

    A promise of type Response if rawResponse is true, a promise of type void otherwise.

getShopperContext

  • If you would like to get a raw Response object use the other getShopperContext function.

    Parameters

    Returns Promise<ShopperContext>

    A promise of type ShopperContext.

  • Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : ShopperContext>

    A promise of type Response if rawResponse is true, a promise of type ShopperContext otherwise.

updateShopperContext

  • If the shopper context exists, it's updated with the patch body.

    • If a new attribute that does not exist in the existing shopper context is present, it is added to the context.
    • If an attribute is already present in the existing shopper context, its value is replaced by the corresponding value from the new shopper context in the request body as follows:
    • custom qualifiers or assignment qualifiers:

    If the individual qualifier key exists, it is overwritten with the new value.

    If the value of the key is set to null, it is deleted from the existing shopper context.

    If an empty custom qualifiers or assignment qualifiers object {} is passed, the entire qualifier object is deleted.

    • effectiveDateTime or sourceCode or clientIp:

    If the new value is set to an empty string (""), it is deleted from the existing shopper context.

    If the new value is set to null, it is ignored.

    If the new value is not empty or null, it overwrites the existing value.

    • customerGroupIds:

    If a list of customerGroupIds exists, it is replaced by the new list of customer group IDs from the request.

    If customerGroupIds is set to an empty array [], the existing list in the shopper context is deleted.

    • geoLocation:

    If it exists, the entire geoLocation object is replaced with the new value.

    If the new value is set to null, it is ignored.

    If an empty geoLocation object {} is passed, it is deleted.

    If you would like to get a raw Response object use the other updateShopperContext function.

    Parameters

    Returns Promise<ShopperContext>

    A promise of type ShopperContext.

  • If the shopper context exists, it's updated with the patch body.

    • If a new attribute that does not exist in the existing shopper context is present, it is added to the context.
    • If an attribute is already present in the existing shopper context, its value is replaced by the corresponding value from the new shopper context in the request body as follows:
    • custom qualifiers or assignment qualifiers:

    If the individual qualifier key exists, it is overwritten with the new value.

    If the value of the key is set to null, it is deleted from the existing shopper context.

    If an empty custom qualifiers or assignment qualifiers object {} is passed, the entire qualifier object is deleted.

    • effectiveDateTime or sourceCode or clientIp:

    If the new value is set to an empty string (""), it is deleted from the existing shopper context.

    If the new value is set to null, it is ignored.

    If the new value is not empty or null, it overwrites the existing value.

    • customerGroupIds:

    If a list of customerGroupIds exists, it is replaced by the new list of customer group IDs from the request.

    If customerGroupIds is set to an empty array [], the existing list in the shopper context is deleted.

    • geoLocation:

    If it exists, the entire geoLocation object is replaced with the new value.

    If the new value is set to null, it is ignored.

    If an empty geoLocation object {} is passed, it is deleted.

    Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : ShopperContext>

    A promise of type Response if rawResponse is true, a promise of type ShopperContext otherwise.

Object literals

Static Readonly apiPaths

apiPaths: object

createShopperContext

createShopperContext: string = "/organizations/{organizationId}/shopper-context/{usid}"

deleteShopperContext

deleteShopperContext: string = "/organizations/{organizationId}/shopper-context/{usid}"

getShopperContext

getShopperContext: string = "/organizations/{organizationId}/shopper-context/{usid}"

updateShopperContext

updateShopperContext: string = "/organizations/{organizationId}/shopper-context/{usid}"

Generated using TypeDoc