---
schema_version: "1"
id: 287adce8531b5a109953701d2f283523fbe228e779f909d7842c9e13afc353f0
title: Personalized Promotions, Shipping, and Payment Methods
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/commerce-api/guides/shopper-context-api-personalized.md
canonical_url: https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/shopper-context-api-personalized.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: b855a5bb1f7e819d689f883d606d687dcb8310e5a3f0d42a0c127f93f902a8fb
products:
  - Composable Storefront
  - Salesforce APIs
---
# Personalized Promotions, Shipping, and Payment Methods

Use the Shopper Context API with other B2C Commerce APIs, such as Basket, Shipping, Payment, and Product, to set up personalized and customized promotions.

## Example: Personalize Products for Device Type

Consider a scenario where you want to personalize the products page based on a shopper’s device type by displaying certain products for shoppers whose device type is mobile.

1. Follow the instructions in [Set and Retrieve Shopper Context](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/shopper-context-api.md#set-and-retrieve-shopper-context).
2. The response of GET products has a new property, “Product Promotion”, which lists all the promotions associated with the product and matching the shopper context criteria, for example: the response might have a discounted price based on the shopper context.

- The merchant can set the effective date in Shopper Context to trigger special price books.
- The merchant can have a dynamic session-based customer group (for example, deviceType = mobile), which can trigger a promotion, such as a 10% discount.

```bash
#!/bin/bash
# Shopper Context Custom Qualifers: https://developer.salesforce.com/docs/commerce/commerce-api/references?meta=shopper-context:Summary
set -euo pipefail

SHORTCODE='kv7kzm78'
ORG='f_ecom_zzrf_006'
SLAS_CLIENT_ID='d4f49c7a-b037-4561-91d9-5c7d547e71b5'
SLAS_CLIENT_SECRET=$SLAS_CLIENT_SECRET
SITE='RefArchGlobal'

# 1. Get Guest Token & USID
BASE="https://$SHORTCODE.api.commercecloud.salesforce.com"
RESPONSE=$(curl "$BASE/shopper/auth/v1/organizations/$ORG/oauth2/token" \
    -su "$SLAS_CLIENT_ID:$SLAS_CLIENT_SECRET" \
    -d 'grant_type=client_credentials')

TOKEN=$(echo $RESPONSE | jq -r '.access_token')
USID=$(echo $RESPONSE | jq -r '.usid')

# 2. Set Shopper Context
curl "$BASE/shopper/shopper-context/v1/organizations/$ORG/shopper-context/$USID" \
    -sX 'PUT' \
    -H "Authorization: Bearer $TOKEN" \
    -H 'Content-Type: application/json' \
    -d '{
        "customQualifiers": {
            "deviceType": "mobile"
        }
    }'

# 3. Get a Product with a Promotion
curl "$BASE/product/shopper-products/v1/organizations/$ORG/products/25493613M?siteId=$SITE" \
    -sH "Authorization: Bearer $TOKEN" \
    | jq -r '.productPromotions'
```

## Example: Personalized Shipping and Payment Method

Consider a scenario where you want to personalize your products page based on a shopper’s device type, for example: for shoppers using a mobile device, create a promotion that provides 10% off with free shipping and the option to pay using Google pay:

![Visualization showing personalized shopper context data and targeting](https://developer.salesforce.com/docs/media/commerce-api/shopper-context-personalized.png)

1. Follow the instructions in [Set and Retrieve Shopper Context](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/shopper-context-api.md#set-and-retrieve-shopper-context).
2. Create Session-based Customer Groups:

- The Shopper Context API works with session-based customer groups.
- Create a session-based customer group and make sure the attribute used in the customer group matches the shopper context qualifier.

![Diagram showing shopper context session data management and synchronization](https://developer.salesforce.com/docs/media/commerce-api/shopper-context-session.png)

**note:** The custom attribute set in the dynamic customer group in Business Manager and the custom qualifier set in the API must match. As a best practice, use only those qualifiers that exist in dynamic session-based customer groups and assignments. In this example, `deviceType` is the attribute used in customer group and shopper context. This Shopper Context data is then used to retrieve customer groups to which a particular shopper belongs, and activates any experiences that are mapped to a particular customer group.

3. Set Shopper Context Parameters

To set the context, use `PUT` `https://{shortCode}.api.commercecloud.salesforce.com/shopper/shopper-context/v1/organizations/{organizationId}/shopper-context/{usid}`

```json
{
  "customQualifiers": {
    "deviceType": "mobile",
    "countryCode": "EU"
  }
}
```

## See Also

- [createShopperContext](https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-context?meta=createShopperContext)
- [Shopper Login (SLAS)](https://developer.salesforce.com/docs/commerce/commerce-api/references/auth?meta=Summary)
- [Assign a Price Book or Promotion to a Specific Store in B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_assigning_a_pricebook_or_promotion_specific.htm&type=5) in _Salesforce Help_
