Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

Sitecore Commerce Integration with View and Action API

January 13, 2020
Sitecore Commerce Integration with View and Action API
Ketan Garala
Ketan Garala
CTO, Sitecore MVP
sitecore-commerce-integration-with-view-and-action-api
sitecore-commerce-integration-with-view-and-action-api-1

External systems can exchange order-related information using the Orders Entity Views and Actions API.

The Views and Actions API is an authoring API designed to service a business user interface and is not optimized for integration scenario.

You should consider the following when using the Views and Actions API for your commerce integration:

  • The Views and Actions API can only process one Commerce entity at the time and does not support batch processing.

  • The Views and Actions API carries more overhead than the Commerce web service API. A call to the Views and Action API is typically a 3-step process that requires getting the action’s view, modifying the view’s properties with updated values, and then executing the action.

sitecore-commerce-integration-with-view-and-action-api-2

Authoring API

Commerce views are exposed via the Authoring API. This Authoring API is based on OData, but is significantly simplified and more dynamically structured to support a data-driven user experience.

The Authoring API targets authoring and management experiences, while the Shops API targets runtime experiences for a shop or storefront. The Authoring API is logically separated from the Shops API to allow more direct control over the availability of functionality in different engine roles.

For example, you may want the Authoring API to be accessible on an internal instance of the Commerce Engine, but not on the Commerce Engine instance that is serving storefronts.

Example of View and Action API

You can only add a line to an order when the status of the order is on hold.

To add a line item to a pending order using C#:

Get the entity view (the request must specify the order ID), for example:

  1. DataServiceQuerySingle query = container.GetEntityView($”Entity-Order-{orderId}”, “AddLineItem”,

  2. “AddLineItem”, string.Empty)

    EntityView view = Proxy.GetValue(query);

    Specify the line item property and the quantity, for example:

  3. var itemProperty = view.Properties.FirstOrDefault(p => p.Name.Equals(“Item”));

  4. Value = “Adventure Works Catalog|AW188-06|20”;

  5. var quantityProperty = view.Properties.FirstOrDefault(p => p.Name.Equals(“Quantity”)); quantityProperty.Value = “1”;

    Execute the action:

  6. CommerceCommand command = Proxy.DoCommand(container.DoAction(view));

As shown in above example, calls to the Orders Views and Actions API typically include the following steps:

  • Getting the action’s view.

  • Modifying the view’s properties values (as required).

  • Executing the action.

Note:

For any API calls to the XC Commerce Engine, you must:

  • Provide a valid authorization token.

  • Build or re-use a container class.

Let us have coffee together and discuss your requirement for sitecore experience commerce. Mail us at info@addact.net.


YOU MAY ALSO LIKE