Coupons, Gift Certificates, and Bonus Products

This topic covers less common use cases for working with baskets.

Add a Coupon to a Basket 

  1. Configure coupons using the information in Using Coupons as Promotion Qualifiers for B2C Commerce.
  2. Get a guest token.
  3. Create a basket.
  4. Add a coupon to the basket using the addCouponToBasket endpoint.
1echo '--> Create basket...'
2curl "$BASE_BASKET/baskets?siteId=$SITE" \
3 -sSfH "Authorization: Bearer $TOKEN" \
4 -H "Content-Type: application/json" \
5 -d '{
6"productItems": [{ "quantity": 1, "productId": "750518699585M"}],
7"couponItems": [{ "code": "menssuits" }]
8}' | jq -r '.couponItems'

For additional code examples, see addCouponToBasket.

Gift Certificates 

For gift certificate overview information and how to create a gift certificate, see Gift Certificates.

Use the Shopper Baskets addGiftCertificateItemToBasket endpoint to add a gift certificate to a basket, as shown in the following example:

1curl "$BASE_BASKETS/$BASKET_ID/gift-certificate-items?siteId=$SITE" \
2   -sS --fail-with-body \
3    -H "Authorization: Bearer $TOKEN" \
4    -H "Content-Type: application/json" \
5  -d '{
6  "amount": 1,
7  "recipientEmail": "miller@salesforce-test.com",
8  "shipmentId": "me"
9}'

Create a Basket and Add Bonus Products With Choice 

  1. Configure the bonus product in Business Manager.
  2. Get a guest token.
  3. Create a basket.
  4. Add one or more products that are associated with a bonus product choice promotion using the createBasket or addItemToBasket endpoint.
  5. After a product is added to the basket, applicable bonus items become available. The basket response includes a property called bonusDiscountLineItems, which is a set of bonus products from which a customer can choose.
  6. Copy the productId and the bonusDiscountLineItemId from the response and use it to select the bonus product using the addItemToBasket endpoint. Quantity is a compulsory field and cannot exceed the number of bonus products allowed in the promotion. In this case, it is 1.
1echo '--> Create basket...'
2RESPONSE=$(
3    curl "$BASE_BASKET/baskets?siteId=$SITE" \
4        -sS --fail-with-body \
5        -H "Authorization: Bearer $TOKEN" \
6        -H "Content-Type: application/json" \
7        -d '{"productItems": [{ "quantity": 1, "productId": "750518894553M"}]}'
8)
9BASKET=$(echo $RESPONSE | jq -r '.basketId')
10echo $RESPONSE | jq -r '.bonusDiscountLineItems'
11BONUS=$(echo $RESPONSE | jq -r '.bonusDiscountLineItems[0].id')
12
13echo '--> Add the bonus product...'
14curl "$BASE_BASKET/baskets/$BASKET/items?siteId=$SITE" \
15    -sS --fail-with-body \
16    -H "Authorization: Bearer $TOKEN" \
17    -H "Content-Type: application/json" \
18    -d '[{ "quantity": 1, "productId": "793775370033M", "bonusDiscountLineItemId": "'$BONUS'"}]' \
19 | jq '.productItems'

The previous script adds a product with bonus products to the basket. The first bonus product available in the bonusDiscountLineItems array is added to the basket.