Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Remove LineItem form Order via API (REST, GraphQL)

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 4 (4)

Brian_S
Shopify Partner
171 21 44

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
crpatel
Shopify Partner
18 0 3

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

xdoomx
Shopify Partner
4 0 0

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

Sudhir
Shopify Partner
7 1 0

@Dmitriy_97 @crpatel @Brian_S  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.