SDK Example: Create a Basket from an Asset (Fall ‘20)

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

1// Instantiate the input object for assetToBasket to specify parameters
2const input = digitalCommerce.createAssetToBasketInput();
3input.catalogCode = "Phones"; // use your Catalog Code
4input.basketAction = "assetToBasket";
5input.isLoggedIn = true;
6input.canCreateBasket = false; // optional - default is false
7input.context = '{"accountId":"YOUR ACCOUNT ID", "contractId":"YOUR CONTRACT ID"}';
8input.validatePrice = true; // optional - default is true
9input.validateAction = true; // optional - default is true
10input.rootAssetIds = "02i4P000009ion5QAA,02i4P000009ion6QAA";
11input.requestDateTime = "2019-08-10T00:00:000z"; // date or date time in UTC format.
12
13// Invoke assetToBasket API via method assetToBasket()
14digitalCommerce
15  .assetToBasket(input)
16  .then(response => {
17    Logger.info(
18      "Vlocity digital commerce assetToBasket: " + JSON.stringify(response)
19    );
20  })
21  .catch(error => {
22    Logger.info("assetToBasket apexrest call failed" + error);
23 });

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.”