SDK Example: Save the Cart (Winter ‘20)

Use the example SDK code in this topic to save the cart by creating an order for the specified basket.

1// Instantiate the input object for saveCart to specify parameters
2const input = digitalCommerce.createSaveCartInput();
3input.email = "YOUR EMAIL ID";
4input.catalogCode = "CATALOG CODE";
5input.cartContextKey = "CART CONTEXT KEY";
6
7// Invoke saveCart API
8digitalCommerce
9  .saveCart(input)
10  .then(response => {
11    Logger.info(
12      "Vlocity digital commerce saveCart: " + JSON.stringify(response)
13    );
14  })
15  .catch(error => {
16    Logger.info("saveCart apexrest call failed" + error);
17  });

Possible error conditions:

“SaveCartInput::getRequestPayload() must have email.”

“SaveCartInput::getRequestPayload() must have catalogCode.”

“SaveCartInput::getRequestPayload() must have cartContextKey.”