Calculate Refund API : Refund line items cannot remove more than the fulfillable quantity

Yes I am aware there’s a previous post : https://community.shopify.com/c/shopify-apis-and-sdks/refund-line-items-cannot-remove-more-than-the-fulfillable/m-p/646473#M43799

This was happening on my live Shopify app, the Calculate Refund API returns a HTTP status 422 Error with message “cannot remove more than the fulfillable quantity.” , if I set the “restock_type” of the refund_line_items to “cancel”.

But if I set it to “return” , then it returns back a proper response, and the “restock_type” returned in the response is “cancel” !

This workaround works but I am afraid it might mess up inventory of other orders if the response returned back somehow is not “cancel” if I put in “return” as input.

I would be really thankful if any Shopify Staff can look into this issue as this has caused issues to merchants using my app.

The Request ID is 24f742a0-0e64-48ae-9f94-d86fb5d836f8

I ran into this issue today - and was not able to find a solution on the internet. Here is how I solved it

Steps to recreate this issue:

  1. Create an order with more than one items.
  2. Go to your admin, fulfil one of the items.
  3. Attempt the request - it will throw this error that you are seeing.

Why does it happen?
In refund_line_items: You could be sending quantity for both the items (but since you had already fulfilled some of the items, the quantity needs to be decreased) When you chooserestock_type to cancel, you must only send the quantity which is unfulfilled for the variant.

  • quantity: The refunded quantity of the associated line item.

  • restock_type: How this refund line item affects inventory levels. Valid values:

    • cancel: The items have not yet been fulfilled. The canceled quantity will be added back to the available count. The number of fulfillable units for this line item will decrease.