SDK Example: Delete From Basket (Fall ‘19)

Use the example SDK code in this topic to do an addToBasket with basketAction=DeleteFromBasket. The call must have deleteBundleNumber as an input parameter.

1// Instantiate the input object for the addToBasket method to specify parameters.
2const input = digitalCommerce.createAddToBasketInput();
3// Use your AWS gateway.
4input.anonymousSiteUrl = "https://mubnr8cjgl.execute-api.us-west-2.amazonaws.com/prod/dc";
5// Use your Catalog Code.
6input.catalogCode = "Mobiles";
7// Delete an offer that was added to basket.
8input.basketAction = "DeleteFromBasket";
9input.forceInvalidateCache = true;
10
11// The basket item list grows from the bottom up. For example: if you add products A, B, and C in that order,
12// the JSONResult.records list would be C,B,A with respective numbering as 0,1,2.
13// The 0 item will always be the most recent addition.
14input.deleteBundleNumber = 0;
15
16// Invoke the Basket API via the addToBasket() method.
17digitalCommerce
18.addToBasket(input)
19.then(response => {
20  Logger.info(
21    "Vlocity digital commerce addToBasket with basketAction=DeleteFromBasket for anonymous user: " +
22      JSON.stringify(response)
23  );
24})
25.catch(error => {
26  Logger.info(
27    "addToBasket with basketAction=DeleteFromBasket for anonymous user rest call failed" +
28      error
29  );
30});

Possible error conditions:

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

“AddToBasketInput::getAnonymousRestUrl() must have anonymousSiteUrl.”

“AddToBasketInput::getAnonymousSiteRestUrl() must have catalogCode.”

“AddToBasketInput::getPostBody() must have basketAction.”

“AddToBasketInput::getPostBody() must have deleteBundleNumber when basketAction is ‘DeleteFromBasket’.”