Add Multiple Products to a Basket

You can add multiple products to a basket at one time using the Basket API. For example, a user might select multiple products and add them to the Basket using a single transaction.

Multi-add functionality works for both known and anonymous users. The basket is validated after the products are added.

  • The Catalog should have CatalogCodec populated; spaces are not allowed in CatalogCodec.

  • Products should have ProductCode populated; spaces are not allowed in ProductCode.

  • Promotions should have Codec populated; space are not allowed in Codec.

  • The product catalog should be present with products and promotions attached to it as records under the CatalogProductRelationship__c object.

  • The product catalog should be attached to a default pricelist through the DefaultPriceListc field on the Catalogc object.

  • Price list entries should exist for all products attached to the catalog.

  • Create a custom setting called CacheAPIFields' with the value set to True in the CPQ Configuration Setup.

  • Ensure you have run the following batch jobs to populate the cache:

    • Context combinations

    • Offer Details

    • Pricing results

The API cache is generated incrementally with successive calls for this API, and is not pre-generated as is the case with some of the other APIs.

/services/apexrest/{namespace}/v3/catalogs/{catalogcode}/basket/{cartContextKey}

POST

ParameterDescription
CatalogCodeThe code of the catalog whose product is being queried.
cartContextKeyA persistent cartContext hash key to maintain existing basket. Leave blank to create a new basked. For example: /v3/catalogs/{CATALOGCODE}/basket?urlParam=value
basketAction

Choose an action type.

AddWithNoConfig If adding directly from offerCode; supplied to the offer parameter. AddAfterConfig If adding from configured offerDetails; supplied to the productConfig parameter.

isDebug

Set this parameter to true for debugging.

ParameterDescription
contextProvide context dimensions as part of context param; examples given at the end
productConfigProvide configured offer details taken from response of configure API to add configured offer to cart. It will contain array in case of multi-add.
sessionKeyPersisting session Key that contains the combination of Order and BasketKey for fresh basket, don't pass anything
offerOffer code of the product/promotion being added has to be passed. It will contain array in case of multi-add.

This API provides the ability for a user to add offers to a virtual basket maintained by the user interface. The basket is tracked using the cartContextKey in the URL. For an empty basket, there is no need to pass the cartContextKey.

Depending upon the parameters passed along in the POST body the Orders are either picked from the Session else the pseudo Accounts and Orders are created. This changes the time for processing.

For an existing basket with COMPLETECACHEMISS, if the sessionKey is passed in the POST body params the existing Order is used to process else a new Account and Order are created.

  • The cartContextKey is returned as part of the response of a successful basket operation.

  • The sessionKey is returned as a part of a successful basket operation. The sessionKey is used to track the Order used for the current basket.

  • The API uses cartContext to track existing basket contents and appropriate context parameters to price products and run context rules.

  • The API uses the sessionKey to store the Order Id used to create the basket against the Basket ID. This provides performance improvement by avoiding creation of new Account and Order for every API call for a CACHE MISS scenario.

  • If pre-cached result is present, that will be returned in case it isn't, this will be treated as a cache-miss and handled (also resulting in a corresponding cache entry)

When the basket is empty, add an item to a basket without configuring.

Response body (truncated):

When basket is empty, add an item to a basket after configuring.

When basket is empty, add one offer with configuration and another without configuration.

Here is the response, truncated: