SDK Example: Get Cart Details (Fall '20 version)

Use the example SDK code in this topic to obtain details about a cart.

// Instantiate the input object for getItemsInCart to specify parameters
const input = digitalCommerce.createGetItemsInCartInput();
input.catalogCode = "Phones"; // use your Catalog Code
input.cartContextKey = "01tf2000007Rb9JAAS"; // use your cart_context_key
input.cacheable = true; // Optional boolean flag to indicate if the sdk call should be cached. Default is false.
input.reload = true; // Optional boolean flag to discard cache and call the api again Default is false.
input.customFields = ["customAttribute__c"]; // optional field which returns your custom attributes or any given keys

// Invoke get basket API via method getItemsInCart()
digitalCommerce
  .getItemsInCart(input)
  .then(response => {
    Logger.info("vlocity get cart items anonymous user rest call" + response);
  })
  .catch(error => {
    Logger.info("get cart items anonymous user rest call failed" + error);
  });



Possible error conditions:

"GetItemsInCartInput::getAPIPath() must have catalogCode."

"GetItemsInCartInput::getAPIPath() must have cartContextKey."