Order edit nodejs + gQL issue

Suppose order has 2 items, Apple and Banana with €5 discount.
I am using node js + gQL function which is adding items and removing items,
now i am removing “Banana” and adding “Cake” product, while “Apple” product remain untouched in order.

In this time, shopify reduces amount of that order-level discount, like -€0.48 instead of €5
and i can’t remove it completely because original ordered item “Apple” is still in order,
how can i solve this matter ?

Any node js hack or gQL hack?

Hi @Harsh_Bundela

Would you like to remove the discount from the order? You can try this API.

orderEditRemoveDiscount - GraphQL Admin

1 Like

Hey Thank you so much for Answer :slight_smile:
but i can’t find any query or mutation to get “discountApplicationId”, do you help me to find out discountApplicationId?

Hey Mate :slight_smile:

I find that how to get discountApplicationID

but i can’t remove order-level discount,
it is showing error like this
“message”: “This discount was applied using a discount code and can’t be removed.”

Any solution for the same? :slight_smile:

Hey @Harsh_Bundela! This is expected behavior with how order-level discount codes work during order edits. When a fixed-amount discount code is applied to an order, Shopify splits it proportionally across line items. So when you remove “Banana,” its share of the discount is removed too, which is why the total drops from 5 EUR to a smaller amount.

The orderEditRemoveDiscount mutation only works on manual discounts. Discount codes, automatic discounts, and script discounts can’t be removed or modified through the Order Edit API. That’s the source of the “can’t be removed” error you’re seeing.

The workaround is to use orderEditAddLineItemDiscount to apply a manual discount to your newly added “Cake” item. You’d calculate the amount that was lost when “Banana” was removed and apply that as a fixed-amount or percentage discount on the new line item. It won’t restore the original discount code label, but it gets you to the same financial outcome. The considerations for editing orders page covers these limitations in more detail. Hope this helps set you on the right path!

You’d calculate the amount that was lost when “Banana” was removed and apply that as a fixed-amount or percentage discount on the new line item. It won’t restore the original discount code label, but it gets you to the same financial outcome. - But how can I calculate that ? I tried a lot but not working, do you have solution or code hack ?

Good question - before you start the edit, query the order’s line items with their discountAllocations. The allocatedAmountSet on the “Banana” line item tells you exactly how much of the order-level discount was assigned to it. That’s the number you apply to “Cake” after adding it. I just tried this myself in my test store, here’re the steps:

  1. Query the original order to get the discount allocation on the item you’re removing:

    query {
      order(id: "gid://shopify/Order/ORDER_ID") {
        lineItems(first: 10) {
          nodes {
            id
            title
            discountAllocations {
              allocatedAmountSet {
                shopMoney {
                  amount
                  currencyCode
                }
              }
            }
          }
        }
      }
    }
    
    

    Find the “Banana” line item and store its allocatedAmountSet.shopMoney.amount (say it’s 4.52).

    1. Start your edit, remove “Banana”, add “Cake” as you’re already doing.

    2. After adding “Cake”, apply the lost discount amount to it using orderEditAddLineItemDiscount:

    mutation {
      orderEditAddLineItemDiscount(
        id: "gid://shopify/CalculatedOrder/CALCULATED_ORDER_ID"
        lineItemId: "gid://shopify/CalculatedLineItem/CAKE_LINE_ITEM_ID"
        discount: {
          fixedValue: { amount: "4.52", currencyCode: EUR }
          description: "Reapplied order discount"
        }
      ) {
        calculatedOrder {
          id
        }
        userErrors {
          field
          message
        }
      }
    }
    
    
    1. Then commit the edit with orderEditCommit.
1 Like

Thank you :heart_eyes: It works!

1 Like

Hey Donal,

This is perfectly working for discount codes, but I applied percentage discount.

It is not working as expected with percentage discounts, do you have any solution that will work for fixed amount discounts + percentage discounts?

Thanks :slight_smile:

Hey @Harsh_Bundela! When you say the percentage discount is “not working as expected,” can you describe exactly what you’re seeing?

The reason I ask is that percentage discount codes and fixed-amount discount codes behave differently during order edits. Fixed-amount discounts split proportionally across line items, so removing an item loses its share of the discount (which is why the fixedValue workaround was needed). Percentage discounts may already extend to newly added items automatically, depending on how the discount was applied.

In the meantime, the orderEditAddLineItemDiscount mutation does support percentage discounts natively through the percentValue field on OrderEditAppliedDiscountInput. So if you do need to manually apply a percentage, you can pass percentValue instead of fixedValue in the discount input. You can get the original percentage from the order’s discountApplications:

query {
  order(id: "gid://shopify/Order/ORDER_ID") {
    discountApplications(first: 10) {
      nodes {
        ... on DiscountCodeApplication {
          code
          value {
            ... on PricingPercentageValue {
              percentage
            }
            ... on MoneyV2 {
              amount
              currencyCode
            }
          }
        }
      }
    }
  }
}

If the value comes back as PricingPercentageValue, you’d use that percentage in your discount input like this:

{
  "discount": {
    "percentValue": 10,
    "description": "Reapplied order discount"
  }
}

Before applying any manual discount though, I’d recommend checking whether the new item already has a discount allocation after you add it to the edit. Query the calculatedOrder.lineItems and look at calculatedDiscountAllocations on the newly added item. If the percentage is already there, adding another one on top would result in a double discount.

Thanks for the solution, but Let me define exact issue.

If order has “Apple” and “banana” with 11% discount.
I will remove “banana” and with its same price i will add “cake”.

so how can i maintain before edit order-price and after edit order-price? same as fixed value,
previous solution works very well with fixed amount discount, but i am unable to find solution for percentage discounts.


also, i have 1 another query, shopify technical support says this is not possible, but if you any hack.
Scenario: If order has “Chocolate-Shake” product with 5eur discount.
Expected Result: I will remove “Chocolate-Shake”, and then i will add “Chocolate” and “Milk” different products.
Chocolate-shake price = Chocolate’s price + Milk’s price

so final order will look like this,
Milk and chocolate product in line items
Removed products: Chocolate-shake

if order is cancelled then total price will be double, because after order cancel, all items will be display in “removed items”, so “chocolate-shake” was already there.

–> To resolve this issue, I was trying to apply 100% discount on chocolate-shake and then i tried to setQuantity 0, but showing me error like this
“message”: “The order has a discount which prevents applying additional discounts to this line item.”

Any hack for this one?

Thanks for clarifying, that makes the percentage discount question straightforward.

The orderEditAddLineItemDiscount mutation supports percentage discounts natively through the percentValue field on OrderEditAppliedDiscountInput. So for your percentage case, the flow is similar to the fixed-amount workaround but you pull the percentage from discountApplications instead of reading allocatedAmountSet:

query {
  order(id: "gid://shopify/Order/ORDER_ID") {
    discountApplications(first: 10) {
      nodes {
        ... on DiscountCodeApplication {
          code
          value {
            ... on PricingPercentageValue {
              percentage
            }
          }
        }
      }
    }
  }
}

If the value comes back as PricingPercentageValue with percentage: 11, then after removing “Banana” and adding “Cake”, apply it to the new line item with percentValue instead of fixedValue:

{
  "discount": {
    "percentValue": 11,
    "description": "Reapplied order discount"
  }
}

I tested this on my own store with a 15% order discount. After removing one item and adding a replacement, orderEditAddLineItemDiscount with percentValue: 15 applied exactly 15% of the new item’s price as the discount allocation. The full flow (begin edit, set quantity to 0, add variant, apply percentage discount, commit) completed without errors. Since “Cake” is the same price as “Banana”, this gives you the same order total before and after the edit.


For the second question about splitting “Chocolate-Shake” into “Chocolate” + “Milk”, the error you’re getting is expected. You can’t add a manual discount (including a 100% discount) to a line item that already has a discount code applied.

The standard approach for this swap should still work though. You can remove “Chocolate-Shake” by setting its quantity to 0 with orderEditSetQuantity, then add “Chocolate” and “Milk” as new line items. Setting quantity to 0 is allowed even on discounted items (I confirmed this in the same test, removing a line item with a discount applied worked with no errors). The restriction is on partial quantity changes and discount modifications, not full removal.

On your cancellation concern, when you remove “Chocolate-Shake” via order edit, the order total adjusts at that point. If the order is later cancelled, the refund is based on the current order state (Chocolate + Milk), not the pre-edit state. The removed “Chocolate-Shake” won’t factor into the refund calculation. The order timeline will show both the edit removal and the cancellation as separate events, but the financials should be correct.