SDK Example: ValidateOffer (Winter ‘20)

Use the example SDK code in this topic to validate an offer.

1// Instantiate the input object for validateOffer to specify parameters
2const input = digitalCommerce.createValidateOfferInput();
3input.catalogCode = "Phones"; // use your Catalog Code
4input.offerCode = "iPhoneX"; // use your Offer Code
5
6// input.offerConfiguration: use digitalCommerce.getSelectedOffer(offerCode)
7input.offerConfiguration = digitalCommerce.getSelectedOffer(offerCode);
8input.customFields = ["customAttribute__c"]; // optional field which returns your custom attributes or any given keys
9input.secureApiCall = false; // set to true if needs secure api calls without context parameters and session key.
10// Invoke ConfigureOfferDetails API via method validateOffer()
11digitalCommerce
12  .validateOffer(input)
13  .then(response => {
14    Logger.info(
15      "vlocity validate offer for anonymous user" + JSON.stringify(response)
16    );
17  })
18  .catch(error => {
19    Logger.info("vlocity validateOffer for anonymous user failed" + error);
20  });

Possible error conditions:

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

“ValidateOfferInput::getAPIPath() must have offerCode.”

“ValidateOfferInput::getPostBody() must have productConfiguration.”