Work with the Inventory Entity Views and Actions API
You can use the XC Inventory Entity Views and Actions API to integrate XC Inventory operations and data a with external business systems.
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.
Get an inventory set (C#)
You can retrieve an inventory set programmatically. The query must specify the id of the inventory set (inventorySetId).
To get an inventory set using C#:
DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-InventorySet-{Id}", "Master", string.Empty, string.Empty);
EntityView view = Proxy.GetValue(query)
Create an inventory set (C#)
You can create an inventory set programmatically.
To create a new inventory set, for example using C#:
-
Get the entity view for the action:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView(string.empty, "Details", "AddInventorySet", string.Empty); EntityView view = Proxy.GetValue(query); -
Specify inventory set details. The request must specify the the name of the new inventory set (
name), the display name (DisplayName), and optionally a description (description).RequestResponsevar Name = view.Properties.FirstOrDefault(p => p.Name.Equals("Name")); var DisplayName = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName")); var Description = view.Properties.FirstOrDefault(p => p.Name.Equals("Description")); Name.Value = "NewSet"; DisplayName.Value = "A New Inventory Set"; Description.Value = "A brand new Inventory Set"; -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));
Update an inventory set (C#)
You can edit the details of an existing inventory set.
To update the details of an inventory set, for example to change its display name and description, using C#:
-
Get the entity view:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-InventorySet-{InventoryId}", "Details", "EditInventorySet", string.Empty); EntityView view = Proxy.GetValue(query); -
Provide the updated details for the inventory set:
RequestResponsevar Description = view.Properties.FirstOrDefault(p => p.Name.Equals("Description")); var DisplayName = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName")); Description.Value = "A new Updated description" DisplayName.Value = "Changed Display Name"; -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));
Associate an item to an inventory set (C#)
You can associate a sellable item to a specified inventory set. For example, when a sellable item is associated with two inventory sets, you can allocate 100 units of a sellable item to inventory set A, and 40 to inventory set B. This lets you manage stock according to your needs.
To associate a sellable item to an inventory set, for example using C#:
-
Get the entity view:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"",string.Empty,"DeleteCatalog", "Entity-Catalog-{CatalogId}"); EntityView view = Proxy.GetValue(query); -
Set the inventory details for the sellable item, for example:
RequestResponsevar SellableItem = view.Properties.FirstOrDefault(p => p.Name.Equals("SellableItem")); // System.String var Quantity = view.Properties.FirstOrDefault(p => p.Name.Equals("Quantity")); // System.Int32 var InvoiceUnitPrice = view.Properties.FirstOrDefault(p => p.Name.Equals("InvoiceUnitPrice")); // System.Decimal var InvoiceUnitPriceCurrency = view.Properties.FirstOrDefault(p => p.Name.Equals("InvoiceUnitPriceCurrency")); // System.String var Preorderable = view.Properties.FirstOrDefault(p => p.Name.Equals("Preorderable")); // System.Boolean var PreorderAvailabilityDate = view.Properties.FirstOrDefault(p => p.Name.Equals("PreorderAvailabilityDate")); // System.DateTimeOffset var PreorderLimit = view.Properties.FirstOrDefault(p => p.Name.Equals("PreorderLimit")); // System.Int32 var Backorderable = view.Properties.FirstOrDefault(p => p.Name.Equals("Backorderable")); // System.Boolean var BackorderAvailabilityDate = view.Properties.FirstOrDefault(p => p.Name.Equals("BackorderAvailabilityDate")); // System.DateTimeOffset var BackorderLimit = view.Properties.FirstOrDefault(p => p.Name.Equals("BackorderLimit")); // System.Int32 SellableItem.Value = $"Entity-SellableItem-{ItemToAssociate}"; Quantity.Value = 10; InvoiceUnitPrice.Value = 20.00; InvoiceUnitPriceCurrency.Value = "USD"; Preoderable.Valu = true; PreOrderAvailabilityDate.Value = DateTimeOffset.Now; PreorderLimit.Value = 2; Backorderable.Value = false; BackorderAvailabilityDate.Value = DateTimeOffset.Now; BackorderLimit.Value = 0; -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));
Disassociate an item from an inventory set (C#)
You can remove a sellable item (sellableItemId), or a specific variant (variationId) of an item, from an inventory set.
To disassociate an item, for example, a sellable item, from a specified inventory set:
-
Get the entity view and disassociate the sellable item:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-InventorySet-{InventorySetId}",string.Empty,"DisassociateSellableItemFromInventorySet", "Entity-SellableItem-{SellableItemId}"); EntityView view = Proxy.GetValue(query); -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));
Transfer inventory (C#)
You can transfer a quantity of units of a sellable items between multiple inventory sets. For example, if you allocated 100 units of a given sellable item to inventory set A, and 40 to set B, but set B is running low, you can transfer additional amounts of the sellable item from inventory set A to inventory set B. This lets you respond to the different needs of your stores and distribution centers.
To transfer inventory from one set to another, for example, using C#:
-
Get the entity view:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-InventorySet-{InventoryId}", "TransferInventory", "TransferInventory", $"Entity-SellableItem-{SellableItemId}"); EntityView view = Proxy.GetValue(query);DataServiceQuerySingle<EntityView>; query = container.GetEntityView($"Entity-Category-{CategoryId}", "Details", "EditCategory", string.Empty); EntityView view = Proxy.GetValue(query); -
Specify the inventory set and quantity to transfer:
RequestResponsevar InventorySet = view.Properties.FirstOrDefault(p => p.Name.Equals("InventorySet")); // System.String var Quantity = view.Properties.FirstOrDefault(p => p.Name.Equals("Quantity")); // System.Int32 InventorySet.Value = $"Entity-InventorySet-{InventorySetToPullFrom}"; Quantity.Value = 10; -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));
Associate a catalog to an inventory set (C#)
You can associate a catalog to an inventory set.
To associate a catalog to an inventory set, for example, using C#:
-
Get the entity view and delete the catalog:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-InventorySet-{InventoryId}", "InventorySetCatalogs", "AssociateCatalog", string.Empty); EntityView view = Proxy.GetValue(query);DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-{ParentType}-{ParentId}",string.Empty,"DeleteCategory","Entity-Category-{CategoryId}"); EntityView view = Proxy.GetValue(query); -
Specify the catalog to associate with the inventory set:
RequestResponsevar Catalog = view.Properties.FirstOrDefault(p => p.Name.Equals("CatalogName")); // System.String Catalog.Value = $"Entity-Catalog-{CatalogId}"; -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));
Disassociate a catalog from an inventory set (C#)
You can disassociate a catalog from an inventory set.
To disassociate a catalog from a inventory set, for example, using C#:
-
Get the entity view and specify and specify the catalog ID to disassociate:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-InventorySet-{InventoryId}", string.Empty, "DisassociateCatalog", {CatalogIdToDisassociate}); -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));