Remove line item from order by API

Topic summary

Goal: remove a line item from an already placed order and add a new variant via API. The requester couldn’t find a direct delete endpoint.

Proposed approach: use the Admin GraphQL orderEditSetQuantity mutation to set the target line item’s quantity to 0, effectively removing it. A code snippet and variables were provided, showing use of CalculatedOrder and CalculatedLineItem IDs. (The mutation example is central to understanding.)

Key terms: CalculatedOrder and CalculatedLineItem are entities used during the order editing process to stage changes before finalizing an order.

Open question: the requester asked how to obtain the CalculatedLineItem ID (e.g., whether it becomes available after the order is placed). This was not answered in the thread.

Additional resource: a community article was shared that discusses removing line items via REST/GraphQL.

Status: no final resolution. Action needed: determine how to retrieve the appropriate CalculatedLineItem ID within the order editing workflow to apply the mutation and then proceed to add the new variant.

Summarized with AI on January 6. AI used: gpt-5.

I want to remove line item from order and add new variant in the order when order is placed. but there is no api for deleting line item from order

I have tried with below article

https://shopify.dev/apps/fulfillment/order-management-apps/order-editing#add-a-new-variant

Hi [email removed]vinodk :waving_hand:

To remove an item from an order, you can use the orderEditSetQuantity mutation and modify the line item quantity to zero. It’ll look something like the below:

mutation ($id: ID!, $lineItemId: ID!, $q: Int!) {
    orderEditSetQuantity(id: $id, lineItemId: $lineItemId, quantity: $q) {
        calculatedOrder {
            id
            lineItems (first:10){
                nodes {
                    id
                    quantity
                    editableQuantity
                    editableQuantityBeforeChanges
                }
            }
        }
    }
}

With variables:

{
    "id": "gid://shopify/CalculatedOrder/28359622774",
    "lineItemId":"gid://shopify/CalculatedLineItem/11789885210742",
    "q": 0
}

Hope that helps!

@ShopifyDevSup
I have tried this method but where i got CalculatedLineItem is it from after place order

Hi @vinodk ,
I find a useful article: https://community.shopify.com/topic/1338407