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

Version: 10.3

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.

To execute any operation in the Sitecore Experience Commerce (XC) system, the calling system must first obtain a valid bearer authorization 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 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.

Add a promotion book (C#)

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:

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

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

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

Get views from a promotion book (C#)

You can use the Views API to retrieve different views of a promotion book.

Note

The Views API uses 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:

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

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

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

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

Edit a promotion book (C#)

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:

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

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

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

Associate a catalog with a promotion book (C#)

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:

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

    RequestResponse
    view.ItemId = "MyCatalog";
  3. Execute the action:

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

Add a promotion (C#)

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:

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

    RequestResponse
    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

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

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

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

Get a promotion's views (C#)

You can retrieve different views of a promotion using the Views API.

To retrieve a promotion's master view:

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

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

To retrieve a promotion's qualifications view:

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

To retrieve the promotion's benefits view:

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

To retrieve the promotion's items view:

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

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

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

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

Edit a promotion (C#)

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:

    RequestResponse
    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".

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

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

Add a qualification (C#)

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

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

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

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

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

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

Edit a qualification (C#)

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:

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

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

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

Add a benefit (C#)

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

    RequestResponse
    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.

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

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

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

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

Edit a benefit (C#)

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:

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

    RequestResponse
    var amountProperty = view.Properties.FirstOrDefault(p =&gt; p.Name.Equals("AmountOff"));
    amountProperty.Value = "20";
  3. Execute the action:

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

Delete a benefit (C#)

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:

    RequestResponse
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, string.Empty, "DeleteBenefit", benefitId));
  2. Execute the action:

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

Add an item to a promotion (C#)

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:

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

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

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

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

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

Removing an item from a promotion (C#)

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:

    RequestResponse
    string promotionId = $"Entity-Promotion-{promotionFriendlyId}";
    EntityView view = Proxy.GetValue(container.GetEntityView(promotionId, string.Empty, "RemoveItem", itemId));
  2. Execute the action:

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

Add a public coupon to a promotion (C#)

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:

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

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

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

Add a private coupon to a promotion (C#)

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:

    RequestResponse
    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.

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

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

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

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

Allocate private coupons (C#)

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:

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

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

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

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

Duplicate a promotion (C#)

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:

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

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

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

Changing a promotion status

Promotions are subject to the promotion approval process. During the approval flow, promotion status can transition as follows:

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:

    RequestResponse
    // 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:

    RequestResponse
    var commentProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Comment"));
    commentProperty.Value = "Requesting approval";
  3. Execute the action:

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

    RequestResponse
    // 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:

    RequestResponse
    var commentProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Comment"));
    commentProperty.Value = "Rejecting approval";
  3. Execute the action:

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

    RequestResponse
    // 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:

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

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

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

    RequestResponse
    var commentProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Comment"));
    commentProperty.Value = "Retracting the promotion";
  3. Execute the action:

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

Delete a promotion (C#)

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:

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

    RequestResponse
    view.ItemId = $"Entity-Promotion-{promotionFriendlyId}";
  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,