Remove unpaid order item via API or GraphQL

Remove unpaid order item via API or GraphQL

Julian29
Shopify Partner
5 0 0

Hi, Developer Team

I wonder that is there any way to remove unpaid order line items via admin REST API or admin GraphQL?

image.png

Replies 3 (3)

ShopifyDevSup
Shopify Staff
1453 238 498

Hi @Julian29 - thanks for reaching out. This is a great question! There is a way to remove unpaid order line items through our GraphQL Admin API. There's a guide here in our docs that goes over how to use the API to make edits to existing orders. You'll want to use the orderEditSetQuantity mutation to do this. Basically, in the API call's variables, you would just want to set the line item's quantity value to 0 and it will remove the unpaid line item from the order. 

 

Hope this helps - let us know if we can clarify anything on our end.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Julian29
Shopify Partner
5 0 0

Hi ShopifyDevSup,

 

Thank you for your answer.

 

Actually, I know how to edit existing orders. However, I have no idea which order line item is unpaid.

ShopifyDevSup
Shopify Staff
1453 238 498

Hi @Julian29!

 

TL;DR: There is no single API call that can determine which item is "unpaid" because this is a fundamental misunderstanding of the Order object. Developing an app around this idea requires a clear purpose and for the app to do the logic.


Adding a product to an Order increases the total cost of the Order, so there is no specific "unpaid item" on an Order. If a product is added to an order after payment there are many ways that payment of the order can be balanced, including removing any product or products that would bring the balance back to zero. This is fundamental to understanding a Shopify Order.


Removing an "unpaid item" with the API would require your app to determine what makes a specific item "unpaid". Consider a merchant using the Shopify Admin to do this. The merchant knows what item they added because they added it, therefore they know what item to remove. If they forget which item they added, they can look down at the Order timeline and see when the order was paid for and what was added to the order after payment. If multiple things were added and removed, they can reason out for themselves what they consider "unpaid" and remove it.


Now consider your app that wants to remove these "unpaid" items. I can think of a few possible solutions but they require asking some questions of your app's purpose:

  • If your app is the thing adding the product in the first place, then marking the order with a metafield that defines which line item it added would allow the app to easily identify and remove that line item
  • An Order management app is likely subscribed to order update webhooks. Your app could use these to compare to a previous "version" of the order the app has stored on your database and, from there, determine which item is new
  • While it's probably the most complex and easily breakable "solution", your app could analyze the Order's Events to determine if a product was added before or after payment. This is complicated by any number of factors such as more than one item being added or removed or multiple payments, requiring your app to determine which payment is the one that matters, or which product, etc.

I would recommend considering the relationship your app has with these "unpaid items" in terms of order flow, and then start building in a way that compliments or enhances the merchant's experience with Shopify. Simply removing a product from an order when a customer doesn't want to settle the bill is a function of the Shopify Admin already.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog