If you would like to get a raw Response object use the other createShopperContext function.
An object containing the options for this method.
A promise of type void.
An object containing the options for this method.
Set to true to return entire Response object instead of DTO.
A promise of type Response if rawResponse is true, a promise of type void otherwise.
Get a shopper's context based on the shopperJWT.
If you would like to get a raw Response object use the other deleteShopperContext function.
An object containing the options for this method.
A promise of type void.
Get a shopper's context based on the shopperJWT.
An object containing the options for this method.
Set to true to return entire Response object instead of DTO.
A promise of type Response if rawResponse is true, a promise of type void otherwise.
If you would like to get a raw Response object use the other getShopperContext function.
An object containing the options for this method.
A promise of type ShopperContext.
An object containing the options for this method.
Set to true to return entire Response object instead of DTO.
A promise of type Response if rawResponse is true, a promise of type ShopperContext otherwise.
If the shopper context exists, it's updated with the patch body.
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.
An object containing the options for this method.
A promise of type ShopperContext.
If the shopper context exists, it's updated with the patch body.
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.
An object containing the options for this method.
Set to true to return entire Response object instead of DTO.
A promise of type Response if rawResponse is true, a promise of type ShopperContext otherwise.
Generated using TypeDoc
Shopper Context
*# 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:
API Version: 0.0.33import { ShopperContext } from "commerce-sdk-isomorphic"; const clientConfig = { parameters: { clientId: "XXXXXX", organizationId: "XXXX", shortCode: "XXX", siteId: "XX" } }; const shopperContextClient = new ShopperContext(clientConfig);
Last Updated: