SDK Example: Get Cart Details (Fall ‘19)

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

1// Instantiate the input object for getItemsInCart to specify parameters
2const input = digitalCommerce.createGetItemsInCartInput();
3input.catalogCode = "Phones"; // use your Catalog Code
4input.cartContextKey = "01tf2000007Rb9JAAS"; // use your cart_context_key
5input.cacheable = true; // Optional boolean flag to indicate if the sdk call should be cached. Default is false.
6input.reload = true; // Optional boolean flag to discard cache and call the api again Default is false.
7input.customFields = ["customAttribute__c"]; // optional field which returns your custom attributes or any given keys
8
9// Invoke get basket API via method getItemsInCart()
10digitalCommerce
11  .getItemsInCart(input)
12  .then(response => {
13    Logger.info("vlocity get cart items anonymous user rest call" + response);
14  })
15  .catch(error => {
16    Logger.info("get cart items anonymous user rest call failed" + error);
17  });

Possible error conditions:

“GetItemsInCartInput::getAPIPath() must have catalogCode.”

“GetItemsInCartInput::getAPIPath() must have cartContextKey.”