Remove LineItem form Order via API (REST, GraphQL)

Hello everyone!

Is it possible to remove one LineItem from Order via GraphQL or REST?
I need to remove LineItem from order, in documentation says that it is possible but there are no API to remove LineItem!!
If someone has done this before, can help me with this issue? Or may be Shopify Support can tell me how can I do it?

Based on what I’ve seen and been able to do, the documentation is incorrect (or a typo) at the top of this example:

https://shopify.dev/api/examples/order-editing#types-of-edits-to-an-order

It lists what edits are possible:

  • Add new variant line items
  • Add new custom line items
  • Remove line items
  • Alter line item quantities

But I think that was supposed to be “Remove line item discounts”.

This seems to be the full list:

Yes, It is possible to remove line item from the order.

I have followed instructions on this link.

To follow instructions on this page you will require basic understanding of Graphiql, and it will be easier to test it by using the Graphiql app by shopify. Please install this app in your store and ensure that required permission(write_order_edits) are selected while you install.

To remove the line item I have followed following steps:

  1. orderEditBegin
mutation orderEditBegin($id: ID!) {
  orderEditBegin(id: $id) {
    userErrors {
      field
      message
    }
    calculatedOrder {
     	id
      lineItems(first: 5){
        edges{
          node{
            id
            quantity
          }
        }
      }
      originalOrder{
        lineItems(first:5){
          edges{
            node{
              id
            }
          }
        }
      }
      
    }
  }
}

provide this as query variable. replace <<order_id>> with your order id. you can find this id in the address bar of your browser when you open the order from admin.

{
  "id": "gid://shopify/Order/<

2. changeLineItemQuantity

replace <<calculated_order_id>> and <<calculated_lineitem_id>> in the following code. you should have received these in the response of step 1 mutation. Notice that I have specify quantity: 0 to remove the line item

```javascript
mutation changeLineItemQuantity {
  orderEditSetQuantity(id: "gid://shopify/CalculatedOrder/<

3. commitEdit

replace the <<calculated_order_id>> in the following code snipped

```javascript
mutation commitEdit {
  orderEditCommit(id: "gid://shopify/CalculatedOrder/<

after this step you will be able to check these changes in the Admin
2 Likes

How could I run this code in a Flow or some other way?

@Dmitriy_97 @crpatel @Brian_S_1 Did you actually find the solution for this. We are unable to do so by following this Remove line items (API) from this for the orders that are fulfilled, returned and the order that has duties and taxes applied. It will be of great help.