Work with the Catalog Entity Views and Actions API

Version: 10.3

External systems can exchange catalog-related information using the Catalog Entity Views and Actions API.

Note

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 a catalog (C#)

You can use the Entity Views and Actions API to retrieve a Commerce catalog using C#.

To retrieve a catalog:

RequestResponse
DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Catalog-{Id}", "Master", string.Empty, "Entity-Catalog-{CatalogId}");
EntityView view = Proxy.GetValue(query);

Create a catalog (C#)

You can use the Entity Views and Actions API to create a new catalog using C#.

To create a catalog:

  1. Get the entity view:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($string.empty, "Details", "AddCatalog", string.Empty);
    EntityView view = Proxy.GetValue(query);
  2. Provide the name and the display name of the new catalog:

    RequestResponse
    var Name = view.Properties.FirstOrDefault(p => p.Name.Equals("Name"));
    var DisplayName = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName"));
    Name.Value = "ANewCatalog";
    DisplayName.Value = "A New Catalog";
  3. Execute the action:

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

Update the details of a catalog  (C#)

You can use the Entity Views and Actions API to modify information details related to a catalog.

To modify a catalog details using C#:

  1. Get the entity view for the catalog details:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Catalog-{CatalogId}",  Details", "EditCatalog", string.Empty);
    EntityView view = Proxy.GetValue(query);
  2. Provide the new catalog details, for example the catalog name or display name:

    RequestResponse
    var DisplayName = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName"));	
    DisplayName.Value = "A Newly Renamed Catalog"
    
  3. Execute the action:

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

Delete a selected a catalog (C#)

You can use the Entity Views and Actions API to delete a catalog using C#.

To delete a selected catalog:

  1. Get the entity view for the catalog:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"",string.Empty,"DeleteCatalog", "Entity-Catalog-{CatalogId}");
    EntityView view = Proxy.GetValue(query);
  2. Execute the delete action:

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

Get a category (C#)

You can use the Entity Views and Actions API to retrieve a catalog category using C#.

To get a category:

RequestResponse
DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-{ParentType}-{ParentId}", string.Empty, string.Empty, "Entity-Category-{CategoryId}");
EntityView view = Proxy.GetValue(query);

Create a category (C#)

You can use the Entity Views and Actions API to create a catalog category using C#.

To create a catalog category:

  1. Get the entity view:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-{ParentType}-{ParentId}", "Details", "AddCategory", string.Empty);
    EntityView view = Proxy.GetValue(query);
  2. Provide the new category details, including the name of the category, the display name, and a description, for example:

    RequestResponse
    var 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 = "ANewCategory";
    DisplayName.Value = "A New Category";
    Description.Value = "A Category to hold samples";
  3. Execute the action:

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

Update a category (C#)

You can use the Entity Views and Actions API to update the details of a category using C#.

To update the information details of a category:

  1. Get the entity view:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Category-{CategoryId}", "Details", "EditCategory", string.Empty); EntityView view = Proxy.GetValue(query);
  2. Provide the new details for the category, for example the display name and the description:

    RequestResponse
    var DisplayName = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName"));
    var Description = view.Properties.FirstOrDefault(p => p.Name.Equals("Description"));
    
    DisplayName.Value = "Even Hotter Stuff Category";
    Description.Value = "Like the Sun Steel Works";
  3. Execute the action:

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

Delete a category (C#)

You can use the Entity Views and Actions API to delete a category from a catalog, using C#.

To delete a category from a catalog:

  1. Get the entity view and delete the catalog:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-{ParentType}-{ParentId}",string.Empty,"DeleteCategory","Entity-Category-{CategoryId}");
    EntityView view = Proxy.GetValue(query);
  2. Execute the action:

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

Disassociate a category (C#)

You can use the Entity Views and Actions API to remove the association that links a category and a sub-category, for example to remove the association without deleting the category, using C#.

To remove the association:

  1. Get the entity view:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-{ParentType}-{ParentId}",string.Empty,"DeleteCategory","Entity-Category-{CategoryId}");	
    EntityView view = Proxy.GetValue(query);
  2. Disassociate the category:

    RequestResponse
    var action = view.Properties.FirstOrDefault(p =>; p.Name.Equals("DeleteOption")); action.Value = "Disassociate";
  3. Execute the action: 

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

Do you have some feedback for us?

If you have suggestions for improving this article,