OCAPI Flash

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’s currently only used at the basket document. The presence of a flash indicates a reason why the basket can’t 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:

1exports.validateBasket = function(basketResponse) {
2     basketResponse.addFlash({
3       type: "MyType",
4       message: "My message",
5       path: "my_path",
6       details: {
7           "k1": "v1",
8           "k2": "v2"
9       }
10    });
11    var flashToRemove;
12    for each(f in basketResponse.flashes) {
13      if (f.type == "SomeOtherType") {
14        flashToRemove = f;
15      }
16    }
17    if (flashToRemove != null) {
18       basketResponse.removeFlash(flashToRemove);
19    }
20}

Attention!

The Open Commerce API (OCAPI) is now deprecated. The provisions described in our versioning and deprecation policy fully apply. For all new projects and major refactoring work, use B2C Commerce API (SCAPI) as the default REST API. For additional details, refer to Why Use SCAPI Instead of OCAPI.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!