Remove LineItem form Order via API (REST, GraphQL)

Dmitriy_97
Shopify Partner
2 0 0

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?

Replies 2 (2)
Brian_S
Shopify Partner
44 5 16

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: 

Brian_S_0-1633341608795.png

 

Brian Singer
CTO & Cofounder of Subscription Service - Awtomic
awtomic.com
chiragramjibhai
Shopify Partner
11 0 0

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/<<order_id>>"  
}

 

 

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

 

mutation changeLineItemQuantity {
  orderEditSetQuantity(id: "gid://shopify/CalculatedOrder/<<calculated_order_id>>", lineItemId: "gid://shopify/CalculatedLineItem/<<calculated_lineitem_id>>", quantity: 0) {
    calculatedOrder {
      id
      addedLineItems(first: 5) {
        edges {
          node {
            id
            quantity
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

 

 

3. commitEdit

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

 

mutation commitEdit {
  orderEditCommit(id: "gid://shopify/CalculatedOrder/<<calculated_order_id>>", notifyCustomer: false, staffNote: "I edited the order! It was me!") {
    order {
      id
    }
    userErrors {
      field
      message
    }
  }
}

 

 

 

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