how to edit line items of the order through API?

lesliewong
Shopify Partner
8 0 1

Hello everyone, I want to change the line items of an order, and after hours of searching, I found several apps that could do that. However, I checked admin API, store API etc, all I found is that only notes/ address/ etc can be changed, but not line items (and not quantity/price). So I just wonder how did those apps can change shopify order? Is there anyway I can develop a private app so we can edit line items of orders? Thanks very much.

0 Likes
Jason
Shopify Expert
10360 158 2009

Line items on an Order can not be changed. You'd need to create a new Order. 

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
lesliewong
Shopify Partner
8 0 1

Thanks for reply! Yup, thats what I got after studing through the API doc...

But what really bugs me is that some app are able to do that, such as:

https://apps.shopify.com/order-editor

https://apps.shopify.com/order-editor-by-lion-apps

So I am wondering is there some API not listed, or some API are restricted to normal app developer?? Thanks.

 

 

0 Likes
MrRobot6629
Tourist
4 0 2

For future readers..

 

It is possible to update line items of an existing order now using GraphQL

0 Likes
UncleWu
Tourist
3 0 0

@MrRobot6629 wrote:

For future readers..

 

It is possible to update line items of an existing order now using GraphQL


This function is not yet documented. Have you experimented on your own to find that out?

 

https://shopify.dev/docs/admin-api/graphql/reference/mutation/orderupdate?api[version]=2020-07

0 Likes
MrRobot6629
Tourist
4 0 2

Yes, I can confirm it works. I've implemented it in a store for one of my clients successfully.

 

One thing i found out is that you can't edit line items for order

- Created via API / Import

- Multi-currency orders

 

There might be more exceptions like this but this is what I've found out so far

0 Likes
janusz_mohi
New Member
1 0 0

Is it possible to change the price of an variant when adding it to (or edit) line items - at update DraftOrder or at update Order via REST or GraphQL API?

0 Likes
MrRobot6629
Tourist
4 0 2

Not sure about the edit order item but i believe you can add line item to draft order with custom price

0 Likes
deldrid1
New Member
3 0 0

@MrRobot6629 - can you provide a bit more details on the mutations that you used for this?

 

I have some orders with customAttributes that have the wrong variant selected.  I'd like to update them to be correct but haven't been able to work out how to do that...

0 Likes
MrRobot6629
Tourist
4 0 2

@deldrid1 - You'd need to use a set of mutations to achieve this.

1 - The first mutation you should use is to begin the order edit process. It goes something link this:

mutation beginEdit{
 orderEditBegin(id: ADMIN_GRAPHQL_API_iID GOES HERE){
    calculatedOrder{
      id
    }
  }
}

 This mutation will also return you a calculated order id which you'll have to use in the next step.

2  - The next step would be to add variants to the order. The mutation for that would look something like this:

mutation addVariantToOrder{
		orderEditAddVariant(id: CALCULATED_ORDER_ID, variantId: "gid://shopify/ProductVariant/VARIANT_ID", quantity: 1){
		    calculatedOrder {
		      id
		      addedLineItems(first:5) {
		        edges {
		          node {
		            id
		          }
		        }
		      }
		    }
		    userErrors {
		      field
		      message
		    }
		}
}

 

3 - After making the change to the order, you have to commit the changes now. To do so, you can set up your mutation something like  this:

mutation commitEdit {
  orderEditCommit(id: CALCULATED_ORDER_ID, notifyCustomer: false, staffNote: "XYZ") {
    order {
      id
    }
    userErrors {
      field
      message
    }
  }

 

These are the steps i've followed to edit an order. I never got the chance to work on deleting products from the existing order but if Shopify allows it then i believe the workflow will be the same for deletion as well.