SDK Example: Create a Basket from an Asset (Winter '20)

Use the example SDK code in this topic to create a basket from an existing asset.

// Instantiate the input object for assetToBasket to specify parameters
const input = digitalCommerce.createAssetToBasketInput();
input.catalogCode = "Phones"; // use your Catalog Code
input.basketAction = "assetToBasket";
input.isLoggedIn = true;
input.canCreateBasket = false; // optional - default is false
input.context = '{"accountId":"YOUR ACCOUNT ID", "contractId":"YOUR CONTRACT ID"}';
input.validatePrice = true; // optional - default is true
input.validateAction = true; // optional - default is true
input.rootAssetIds = "02i4P000009ion5QAA,02i4P000009ion6QAA";
input.requestDateTime = "2019-08-10T00:00:000z"; // date or date time in UTC format.

// Invoke assetToBasket API via method assetToBasket()
digitalCommerce
  .assetToBasket(input)
  .then(response => {
    Logger.info(
      "Vlocity digital commerce assetToBasket: " + JSON.stringify(response)
    );
  })
  .catch(error => {
    Logger.info("assetToBasket apexrest call failed" + error);
 });

Possible error conditions:

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

"AssetToBasketInput::getAPIPath() must have context."

"AssetToBasketInput::getAPIPath() must have set isLoggedIn=true."

"AssetToBasketInput::getRequestPayload() must have rootAssetIds."

"AssetToBasketInput::getRequestPayload() must have basketAction."

"AssetToBasketInput::getRequestPayload() must have valid requestDateTime input."