---
title: "Work with the Promotions Entity Views and Actions API (C#)"
slug: "work-with-the-promotions-entity-views-and-actions-api--c--"
abstract: "How to use the Sitecore XC Promotions Entity Views and Actions API to enable external systems to integrate promotion-related data and exchange promotion-related data with other business systems using C# programming."
---
# Work with the Promotions Entity Views and Actions API (C#)

External systems can integrate Sitecore XC promotions-related operation and exchange promotions-related data with other systems using the Sitecore XC Promotions Entity Views and Actions API.

You must include Commerce Engine operations and commands within a container call (using C#) as shown in this [example](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/build-a-container--c--.html "Build a container (C#)").

To execute any operation in the Sitecore Experience Commerce (XC) system, the calling system must first [obtain a valid bearer authorization](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/obtain-an-authentication-token--c--.html "Obtain an authentication token (C#)") token for the Sitecore Identity Server.

The Promotions View and Actions API supports actions to *Add*, *Get*, *Edit* and *Manage Associated Catalogs* for promotions books.

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

<details>
<summary><h2>Add a promotion book (C#)</h2></summary>

You can create a new promotion book programmatically using an API request. Once a promotion book exists, you cannot change its name. You cannot delete a promotion book.

To add a promotion book using C#:

1. Get the entity view:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView(string.Empty, "Details", "AddPromotionBook", string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's properties by specifying a `Name`, a `DisplayName` ,and a `Description`, for example:

    ```

    var nameProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Name"));
    nameProperty.Value = "MyPromotionBook";
    var displayNameProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName"));
    displayNameProperty.Value = "Book Display Name";
    var descriptionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Description"));
    descriptionProperty.Value = "Book Description";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Get views from a promotion book (C#)</h2></summary>

You can use the Views API to retrieve [different views of a promotion book](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/promotions-views.html "Promotions views").

> [!note]
> The Views API uses [Composite EntityViews](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/composite-entityviews.html "Composite EntityViews"). You can request master views, but you can also request child views.

### Retrieve a promotion's book master view

To retrieve a promotion's book master view:

```csharp
DataServiceActionQuerySingle<EntityView> query = container.GetEntityView($"Entity-PromotionBook-{bookFriendlyId}", "Master", string.Empty, string.Empty);
EntityView view = Proxy.GetValue(query);

```

### Retrieve a promotion book's details view

To retrieve a promotion book's details view:

```

query = container.GetEntityView($"Entity-PromotionBook-{bookFriendlyId}", "Details", string.Empty, string.Empty);
view = Proxy.GetValue(query);

```

### Retrieve a promotion book's associated catalogs view

To retrieve a promotion book's associated catalogs view:

```

query = container.GetEntityView($"Entity-PromotionBook-{bookFriendlyId}", "PromotionBookCatalogs", string.Empty, string.Empty);
view = Proxy.GetValue(query);

```

### Retrieve a promotion book's promotions view

To retrieve a promotion book's view:

```

query = container.GetEntityView($"Entity-PromotionBook-{bookFriendlyId}", "Promotions", string.Empty, string.Empty);
view = Proxy.GetValue(query);

```

</details>

<details>
<summary><h2>Edit a promotion book (C#)</h2></summary>

You can change the values of the `DisplayName` and `Description` properties of an existing promotion book. You cannot change it's internal name (the value of the `Name` property). If the request does not specify values, then existing values remain unchanged.

To edit the details of a promotion book:

1. Get the entity view:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-PromotionBook-{bookFriendlyId}", "Details", "EditPromotionBook", string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's properties, for example, by specifying a `DisplayName` or a `Description`, or both, as show in the following example:

    ```csharp
    var displayNameProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName"));
    displayNameProperty.Value = "Edited Book Display Name";
    var descriptionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Description"));
    CommerceCommand command = Proxy.DoCommand(container.DoAction(view));descriptionProperty.Value = "Edited Book Description";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Associate a catalog with a promotion book (C#)</h2></summary>

You associate a catalog to a promotion so that promotions defined in the book can apply to the catalog items. You can associate a promotion book to multiple catalogs, but a catalog can only be associated to one promotion book.

To associate a catalog with a promotion book:

1. Get the entity view:

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

2. Modify the views properties, for example, to specify the catalog you want to associate, for example:

    ```text
    view.ItemId = "MyCatalog";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Add a promotion (C#)</h2></summary>

You create a promotion within a promotion book. Within the promotion book, the name of the promotion must be unique. You cannot change the name of a promotion.

To add a promotion:

1. Get the entity view:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-PromotionBook-{bookFriendlyId}", "Details", "AddPromotion", string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's property to specify the promotion's details, for example:

    ```

    var nameProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Name"));
    nameProperty.Value = "MyPromotion";
    var displayNameProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName"));
    displayNameProperty.Value = "Promotion Display Name";
    var descriptionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Description"));
    descriptionProperty.Value = "Promotion Description";
    var displayTextProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayText"));
    displayTextProperty.Value = "Promotion Text";
    var displayCartTextProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayCartText"));
    displayCartTextProperty.Value = "Promotion Cart Text";
    var validFromProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("ValidFrom"));
    validFromProperty.Value = DateTimeOffset.UtcNow.ToString(CultureInfo.InvariantCulture);
    var validToProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("ValidTo"));
    validToProperty.Value = DateTimeOffset.UtcNow.AddDays(30).ToString(CultureInfo.InvariantCulture);
    var isExclusiveProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("IsExclusive"));
    isExclusiveProperty.Value = "true";
    ```

3. Execute the action

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

    The request returns the promotion's friendly ID as part of the `PromotionAdded` model, for example:

    ```csharp
    PromotionAdded promotionAddedModel = command.Models.OfType<PromotionAdded>().FirstOrDefault();
    string promotionFriendlyId = promotionAddedModel?.PromotionFriendlyId;
    ```

</details>

<details>
<summary><h2>Get a promotion's views (C#)</h2></summary>

You can retrieve [different views of a promotion](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/promotions-views.html "Promotions views") using the Views API.

To retrieve a promotion's master view:

```csharp
DataServiceActionQuerySingle<EntityView> query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "Master", string.Empty, string.Empty);
EntityView view = Proxy.GetValue(query);

```

To retrieve a promotion's details view:

```

query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "Details", string.Empty, string.Empty);
view = Proxy.GetValue(query);

```

To retrieve a promotion's qualifications view:

```

query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "Qualifications", string.Empty, string.Empty);
view = Proxy.GetValue(query);

```

To retrieve the promotion's benefits view:

```

query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "Items", string.Empty, string.Empty);
view = Proxy.GetValue(query);

```

To retrieve the promotion's items view:

```

query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "Items", string.Empty, string.Empty);
view = Proxy.GetValue(query);

```

To retrieve the promotion's public coupon's view:

```

query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "PublicCoupons", string.Empty, string.Empty);
view = Proxy.GetValue(query);
view = Proxy.GetValue(query);

```

To retrieve the promotion's private coupon's view:

```

query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "PrivateCoupons", string.Empty, string.Empty);
view = Proxy.GetValue(query);

```

</details>

<details>
<summary><h2>Edit a promotion (C#)</h2></summary>

You can change the values of an existing promotion's properties.

> [!note]
> You can only make change a to a promotion when it is in the *Draft* state.

To edit a promotion:

1. Get the entity view:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "Details", "EditPriceCard", string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's properties as required, for example:

    > [!note]
    > If no values are provided for `DisplayName` and/or `Description`, current values remain unchanged. The rest of the properties are required. (A property is required when `IsRequired` is set to `"true"`.

    ```

    var displayNameProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayName"));
    displayNameProperty.Value = "Edited Promotion Display Name";
    var descriptionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Description"));
    descriptionProperty.Value = "Edited Promotion Description";
    var displayTextProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayText"));
    displayTextProperty.Value = "Edited Promotion Text";
    var displayCartTextProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("DisplayCartText"));
    displayCartTextProperty.Value = "Edited Promotion Cart Text";
    var validFromProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("ValidFrom"));
    validFromProperty.Value = DateTimeOffset.UtcNow.AddDays(3).ToString(CultureInfo.InvariantCulture);
    var validToProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("ValidTo"));
    validToProperty.Value = DateTimeOffset.UtcNow.AddDays(33).ToString(CultureInfo.InvariantCulture);
    var isExclusiveProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("IsExclusive"));
    isExclusiveProperty.Value = "false";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Add a qualification (C#)</h2></summary>

Qualifications are the conditions you set on a promotion and that need to be met for the promotion benefits to be applied to a shopper's order. [Sitecore XC provides multiple qualifications](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/promotions---qualifications.html "Promotions – qualifications") that can be applied to a promotion.

To add a qualification to a promotion:

1. Get the entity view, for example, to add the *Cart Has \[count\] items?* qualification to the promotion:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, "QualificationDetails", "SelectQualification", string.Empty));
    var conditionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Condition"));
    var availableConditionsPolicy = conditionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault();
    conditionProperties.Value = availableConditionsPolicy?.List.FirstOrDefault(o => o.Name.Equals("CartHasItemsCountCondition")).Name;
    CommerceCommand command = Proxy.DoCommand(container.DoAction(view));
    ```

2. Set the qualification value. In the following example, the item count for the *Cart Has \[count\] items?* is set to *3*:

    ```

    view = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name));
    var countProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Count"));
    countProperty.Value = "3";
    ```

3. Execute the action:

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

    The qualification id is returned in the `QualificationAdded` model, for example:

    ```text
    var qualificationId = addAction.Models.OfType<QualificationAdded>().FirstOrDefault()?.QualificationId;
    ```

</details>

<details>
<summary><h2>Edit a qualification (C#)</h2></summary>

You can make changes to an existing qualification using the Views/Actions API.

To edit a qualification, for example, to edit the *Cart Has \[count\] Items?* qualification, by setting the count property to *5*:

1. Get the entity view:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, "QualificationDetails", "EditQualification", qualificationId));
    ```

2. Edit the qualification's property value as required, for example, to change the item count of the *Cart Has \[count\] Items?* qualification to *5*:

    ```

    var countProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Count"));
    countProperty.Value = "5";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Add a benefit (C#)</h2></summary>

Benefits are the possible discounts that apply to a promotion. The benefits are applied to a customer's order when the qualification conditions for the promotion are met. [Sitecore XC predefines benefits](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/promotions---benefits.html "Promotions – benefits") that you can applied to one promotion. You can add multiple benefits to one promotion.

To add a benefit to a promotion:

1. Get the entity view, for example, to apply the *Get Cart Subtotal \[specific\] Amount Off* benefit to a promotion:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, "BenefitDetails", "SelectBenefit", string.Empty));
    var actionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Action"));
    var availableActionsPolicy = actionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault();
    actionProperty.Value = availableActionsPolicy?.List.FirstOrDefault(o => o.Name.Equals("CartSubtotalAmountOffAction")).Name;
    CommerceCommand command = Proxy.DoCommand(container.DoAction(view));
    ```

2. Set the benefit value property. For example, the following sample sets the *AmountOff* value to *50*.

    ```

    view = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name));
    var amountProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("AmountOff"));
    amountProperty.Value = "50";
    command = Proxy.DoCommand(container.DoAction(view));"CartSubtotalAmountOffAction
    ```

3. Execute the action:

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

    The benefit id is returned using the `BenefitAdded `model, for example:

    ```text
    var benefitId = addAction.Models.OfType<BenefitAdded>().FirstOrDefault()?.BenefitId;
    ```

</details>

<details>
<summary><h2>Edit a benefit (C#)</h2></summary>

You can make changes to an existing benefit by changing its properties value.

To edit a benefit, for example to change the value of the discounted amount in the *Get Cart Subtotal \[specific\] Amount Off* benefit:

1. Get the entity view:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, "BenefitDetails", "EditBenefit", benefitId));
    ```

2. Modify the value of the `"AmountOff"` property, for example, to *20*:

    ```

    var amountProperty = view.Properties.FirstOrDefault(p =&gt; p.Name.Equals("AmountOff"));
    amountProperty.Value = "20";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Delete a benefit (C#)</h2></summary>

You can delete a benefit from a promotion.

To delete a benefit:

1. Get the entity view and include, in the query, the friendly ID of the promotion and the benefit ID that you want to delete, for example:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, string.Empty, "DeleteBenefit", benefitId));
    ```

2. Execute the action:

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

</details>

<details>
<summary><h2>Add an item to a promotion (C#)</h2></summary>

Need to confirm the purpose statement - not sure it jives with the code sample in step 2You add an item (for example, a sellable item or a variant of item) to a promotion so that the promotion applies to individual items (as opposed to apply the promotion at the catalog level).

> [!note]
> You can only change a promotion when it is in the *Draft* state. You cannot modify a promotion that is in the *approved* state.

To add an item to a promotion:

1. Get the entity view:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, "ItemDetails", "AddItem", string.Empty));
    ```

2. Modify the view's properties, for example to add a *not excluded* property to a promotion:

    ```

    var catalogProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Catalog"));
    var availableCatalogsPolicy = catalogProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault();
    catalogProperty.Value = availableCatalogsPolicy?.List.FirstOrDefault(o => o.Name.Equals("MyCatalog"))?.Name;
    var itemIDProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("ItemId"));
    itemIDProperty.Value = "MyProduct|MyCatalog|MyVariant";
    var excludedProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Excluded"));
    excludedProperty.Value = "false";
    ```

3. Execute the action:

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

    The item id is returned using the `PromotionItemAdded `model, for example:

    ```text
    string itemId = command.Models.OfType<PromotionItemAdded>().FirstOrDefault()?.PromotionItemId;
    ```

</details>

<details>
<summary><h2>Removing an item from a promotion (C#)</h2></summary>

You can remove an item from a promotion using the Views and Actions API.

To remove an item from a promotion:

1. Get the entity view, and include, in the query, the friendly ID of the promotion and the item ID you want to remove, for example:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, string.Empty, "RemoveItem", itemId));
    ```

2. Execute the action:

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

</details>

<details>
<summary><h2>Add a public coupon to a promotion (C#)</h2></summary>

A public coupon is a string of text that can be used multiple times.

To add a public coupon to a promotion:

1. Get the entity view:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, "PublicCoupons", "AddPublicCoupon", string.Empty));
    ```

2. Modify the view's properties to specify the `codeProperty.Value` , for example:

    ```

    var codeProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Code"));
    codeProperty.Value = "MyPublicCoupon_ABC123";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Add a private coupon to a promotion (C#)</h2></summary>

A private coupon is a discount code that is assigned to a single customer. You can specify how many private coupons you want to create

To add a private coupon to a promotion:

1. Get the entity view, for example:

    ```csharp
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, "CouponDetails", "AddPrivateCoupon", string.Empty));
    ```

2. Modify the view's properties to specify coupon allocations details. The following is a query to create 20 possible allocations.

    ```

    var prefixProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Prefix"));
    prefixProperty.Value = "before_";
    var suffixProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Suffix"));
    suffixProperty.Value = "_after";
    var totalProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Total"));
    totalProperty.Value = "20";
    ```

3. Execute the action:

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

    The coupon friendly id is returned using the `PrivateCouponGroupAdded` model, for example

    ```text
    string privateCouponId = command.Models.OfType<PrivateCouponGroupAdded>().FirstOrDefault()?.GroupFriendlyId;
    ```

</details>

<details>
<summary><h2>Allocate private coupons (C#)</h2></summary>

You can use the Promotions Views and Actions API to allocate generated private coupons to a specific promotional campaign.

To allocate private coupons:

1. Get the entity view for the action:

    ```csharp
    string groupId = $"Entity-PrivateCouponGroup--{privateCouponId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(groupId, "AllocationDetails", "NewAllocation", string.Empty));
    ```

2. Modify the view's properties, for example, to allocate 10 coupons:

    ```

    var countProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Count"));
    countProperty.Value = "10";
    ```

3. Execute the action:

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

    The list of the allocated coupons code is returned using the `PrivateCouponList` model.

</details>

<details>
<summary><h2>Duplicate a promotion (C#)</h2></summary>

You can duplicate an existing promotion, using the Views and Actions API, to create a new promotion within the same promotion book. The new promotion is in the *Draft* status, which allows you to edit it.

To duplicate a promotion:

1. Get the entity view for the action:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "Details", "DuplicatePromotion", string.Empty);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's properties, for example:

    ```

    var nameProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("PromotionDuplicateName"));
    nameProperty.Value = "MyDuplicatePromotion";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Changing a promotion status</h2></summary>

Promotions are subject to the [promotion approval process](https://doc.sitecore.com/xp/en/users/101/sitecore-experience-commerce/promotion-approval-process.html). During the approval flow, promotion status can transition as follows:

- From *Draft* to *ReadyForApproval* (see [Submit a promotion for approval (C#)](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/work-with-the-promotions-entity-views-and-actions-api--c--.html#UUID-78e158b0-115f-f3e8-a765-b47c7164b674_section-5c799935ef787-idm46420883302976 "Submit a promotion for approval (C#)"))
- From *ReadyForApproval* to *Draft* (see [Reject a promotion (C#)](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/work-with-the-promotions-entity-views-and-actions-api--c--.html#UUID-78e158b0-115f-f3e8-a765-b47c7164b674_section-5c799d283d66b-idm46092393961520 "Reject a promotion (C#)"))
- From *ReadyForApproval* to *Approved* (see [Approve a promotion (C#)](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/work-with-the-promotions-entity-views-and-actions-api--c--.html#UUID-78e158b0-115f-f3e8-a765-b47c7164b674_section-5c799e29b0c20-idm46092394046080 "Approve a promotion (C#)"))
- From *Approved* to *Disabled* (see [Disable an approved promotion](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/work-with-the-promotions-entity-views-and-actions-api--c--.html#UUID-78e158b0-115f-f3e8-a765-b47c7164b674_section-5c79a0b0bfaca-idm46092393607328 "Disable an approved promotion"))

### Submit a promotion for approval (C#)

You can submit a draft promotion for approval.

To request approval for a promotion:

1. Get the view for the action:

    ```csharp
    // requesting approval
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "SetPromotionApprovalStatus", "RequestPromotionApproval", snapshotId);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's properties to request approval:

    ```

    var commentProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Comment"));
    commentProperty.Value = "Requesting approval";
    ```

3. Execute the action:

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

    The status of the promotion changes from *Draft* to *ReadyForApproval*.

### Reject a promotion (C#)

You can reject a promotion when its status is `ReadyForApproval`.

To reject a promotion and set it back to the draft status:

1. Get the view for the action:

    ```csharp
    // rejecting
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "SetPromotionApprovalStatus", "RejectPromotion", snapshotId);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's properties to reject the approval request:

    ```

    var commentProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Comment"));
    commentProperty.Value = "Rejecting approval";
    ```

3. Execute the action:

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

    The promotion returns to the *Draft* status.

### Approve a promotion (C#)

You can approve a promotion when its status is `ReadyForApproval`.

To approve a promotion:

1. Get the view for the action:

    ```csharp
    // approving
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "SetPromotionApprovalStatus", "ApprovePromotion", snapshotId);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's properties to approve the promotion:

    ```

    var commentProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Comment"));
    commentProperty.Value = "Approving";
    ```

3. Execute the action:

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

    The promotion's status changes to *Approved*.

### Disable an approved promotion

You can disable an approved promotion. When you disable a promotion, it remains approved but it is no longer active. You cannot reactivate a disabled promotion.

To disable an approved promotion

1. Get the view for the action:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Promotion-{promotionFriendlyId}", "SetPromotionApprovalStatus", "RetractPromotion", snapshotId);
    EntityView view = Proxy.GetValue(query);
    ```

2. Modify the view's properties to disable the active promotion:

    ```

    var commentProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Comment"));
    commentProperty.Value = "Retracting the promotion";
    ```

3. Execute the action:

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

</details>

<details>
<summary><h2>Delete a promotion (C#)</h2></summary>

You can delete a promotion when it is the *Draft* status.

To delete a promotion:

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

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

2. Modify the view's properties to specify the `promotionFriendlyId`, for example:

    ```text
    view.ItemId = $"Entity-Promotion-{promotionFriendlyId}";
    ```

3. Execute the action:

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

</details>