OCAPI flash 23.2

Flash is a property of documents and contains special information about the document.

Such information could be:
  • a message that the basket contains a product that is no more available.
  • a message that the basket contains a product that has no price.
  • ... and so on.

It is currently only used at the basket document. The presence of a flash indicates a reason why the basket cannot yet be submitted. See examples of basket resource.

In the Scripting API, flashes can be read from, added to or removed from a document using the methods addFlash, removeFlash and flashes or getFlashes(). Flashes can be added to any object within the structure of the document - for example a flash may be added to the baskets billing address with the path $.post_code or to one of the baskets product items with path $.adjusted_price. Before sending the response to the client, such flashes are aggregated to the document and their paths are adjusted appropriately, in our example to $.billing_address.post_code and $.product_items[0].adjusted_price.

Example usage showing addition, listing, and removal of flashes:

exports.validateBasket = function(basketResponse) {
     basketResponse.addFlash({
       type: "MyType",
       message: "My message",
       path: "my_path",
       details: {
           "k1": "v1",
           "k2": "v2"
       }
    });
    var flashToRemove;
    for each(f in basketResponse.flashes) {
      if (f.type == "SomeOtherType") {
        flashToRemove = f;
      }
    }
    if (flashToRemove != null) {
       basketResponse.removeFlash(flashToRemove);
    }
}
X OCAPI versions 15.x and 16.x will be retired on March 31, 2021. For dates and more information, see the OCAPI versioning and deprecation policy and this Knowledge Article.