---
title: "Work with the Orders Entity Views and Actions API (C#)"
slug: "work-with-the-orders-entity-views-and-actions-api--c--"
abstract: "How to perform order-related operations such as putting an order on hold, deleting an order line, adding an order line, or editing an order line."
---
# Work with the Orders Entity Views and Actions API (C#)

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

> [!note]
> The Views and Actions API is an [authoring API](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/authoring-api.html "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.

As [shown in this example](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm45761463057952 "Add an order line (C#)"), 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](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/obtain-an-authentication-token--c--.html "Obtain an authentication token (C#)").
>
> -   [Build or re-use a container class](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/build-a-container--c--.html "Build a container (C#)").

## Work with Orders using the Entity Views and Actions API (C#)

You can use the Entity Views and Actions API to perform the following orders-related operations:

- [Put an order on hold (C#)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm45761463440432 "Put an order on hold (C#)")
- [Delete an order line (C#)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm45837282344784 "Delete an order line (C#)")
- [Add an order line (C#)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm45761463057952 "Add an order line (C#)")
- [Edit an order line (C#)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm45417401286144 "Edit an order line (C#)")
- [Release an order from hold (C#)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm45837281364368 "Release an order from hold (C#)")
- [Undo changes made to an order (C#)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm46408119156416 "Undo changes made to an order (C#)")
- [Cancel hold on an order (C#)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm46031842607872 "Cancel hold on an order (C#)")
- [Return an item (C#)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/work-with-the-orders-entity-views-and-actions-api--c--.html#UUID-1f46b4cf-b74f-54b4-d93e-d6101d82b0ae_section-idm46031843339072 "Return an item (C#)")

<details>
<summary><h3>Put an order on hold (C#)</h3></summary>

You can only put an order on hold when the order status is *pending*.

To put an order on hold using C#:

1. Get the entity view for the action, for example:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "HoldOrder",
    string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Execute the action:

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

</details>

<details>
<summary><h3>Delete an order line (C#)</h3></summary>

You can delete an order line when the order status is *pending*.

To delete a line from a pending order using C#:

1. Get the entity view for the action, for example: 

    ```text
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "DeleteLineItem", lineId);
    ```

2. Execute the action: 

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

</details>

<details>
<summary><h3>Add an order line (C#)</h3></summary>

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#:

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

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", "AddLineItem",
    "AddLineItem", string.Empty)
    EntityView view = Proxy.GetValue(query);
    ```

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

    ```

    var itemProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Item"));
    itemProperty.Value = "Adventure Works Catalog|AW188-06|20";
    var quantityProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Quantity"));
    quantityProperty.Value = "1";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h3>Edit an order line (C#)</h3></summary>

You can only edit an order line when the status of the order is *on hold*.

To modify an order line, for example, change a line item quantity to *5*:

1. Get the entity view for the action for a given order (the request must specify the order ID and the line item ID), for example:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", "EditLineItem",
    "EditLineItem", lineId);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the quantity of the line item to *5*  :

    ```text
    var quantityProperty = view.Properties.FirstOrDefault(p =>; p.Name.Equals("Quantity")); quantityProperty.Value = "5";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h3>Release an order from hold (C#)</h3></summary>

To release an order from the *on hold* status:

1. Get the entity view for the action, for example:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "ReleaseOrder",
    string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Execute the action: 

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

    > [!note]
    > After it has been released, the order returns to the *pending* status.

</details>

<details>
<summary><h3>Undo changes made to an order (C#)</h3></summary>

To undo changes made to an order (while it was *on hold*):

1. Get the entity view for the action, for example:

    ```text
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "UndoOnHoldOrder", string.Empty); EntityView view = Proxy.GetValue(query);
    ```

2. Execute the action:

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

    > [!note]
    > After you undo the changes, the order remains *on hold*.

</details>

<details>
<summary><h3>Cancel hold on an order (C#)</h3></summary>

To cancel the hold on an order using C#:

1. Get the entity view for the action, for example:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "CancelOnHoldOrder", string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Execute the action:

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

> [!note]
> After you cancel the hold, the order returns to the *Pending* status.

</details>

<details>
<summary><h3>Cancel an order (C#)</h3></summary>

You can only cancel orders that are in the *pending* status.

To cancel a pending order using C#:

1. Get the entity view for the action, for example:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "CancelOrder",
    string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Execute the action:

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

    > [!note]
    > After you cancel the hold, the order status changes to *cancelled*.

</details>

<details>
<summary><h3>Return an item (C#)</h3></summary>

You can perform a [return merchandise authorization (RMA)](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-commerce/orders-service---returns.html "Orders service – Returns") request programmatically using the Entity Views and Actions API.

> [!note]
> You can request an RMA when an order status is `completed`.

To perform a RMA request on an order line item using C#:

1. Specify the reason for returning the item, as well as the quantity of this line item to return.  In the following example, the reason for returning is *wrong Item*. The quantity returned is *1*.

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", "RequestRma", "ValidateRmaRequest", lineId);
    EntityView view = Proxy.GetValue(query);
    var reasonProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Option"));
    var availableReasonsPolicy = reasonProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault();
    reasonProperty.Value = availableReasonsPolicy?.List.FirstOrDefault(o => o.Name.Equals("WrongItem")).Name;
    view.Properties.FirstOrDefault(p => p.Name.Equals("Quantity")).Value = 1;
    ```

2. Confirm to proceed with the return request.

    ```csharp
    CommerceCommand command = Proxy.DoCommand(container.DoAction(view));
    view = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name));
    var countryProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Country"));
    countProperty.Value = "3";
    var availableCountryPolicy = optionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault();
    countryProperty.Value = availableCountryPolicy?.List.FirstOrDefault(o => o.Name.Equals("CA")).Name;
    command = Proxy.DoCommand(container.DoAction(view));
    view = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name));
    command = Proxy.DoCommand(container.DoAction(view));
    ```

3. Execute the action:

    ```

    view = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name));
    command = Proxy.DoCommand(container.DoAction(view));command = Proxy.DoCommand(container.DoAction(view));
    ```

</details>