Discussing APIs and development related to customers, discounts, and order management.
mutation
mutation returnLineItemRemoveFromReturn($returnId: ID!, $returnLineItems: [ReturnLineItemRemoveFromReturnInput!]!) { returnLineItemRemoveFromReturn(returnId: $returnId, returnLineItems: $returnLineItems) { return { id } userErrors { field message } } }
variables
{ "returnId": "gid://shopify/Return/10268868783", "returnLineItems": [ { "quantity": 1, "returnLineItemId": "gid://shopify/ReturnLineItem/15804956847" } ] }
I'm receiving this error:
"data": {
"returnLineItemRemoveFromReturn": {
"return": null,
"userErrors": [
{
"field": [
"returnLineItems",
"0",
"quantity"
],
"message": "Return line item has an invalid quantity."
}
]
}
},
I'm not sure how quantity of 1 is invalid.
I'm sure that the ReturnLineItem ID is valid and has a quantity of 1. If I spy on the Network tab in chrome dev tools when I open up the return request in the Shopify admin, there are two items in my return request. One of them matches what I have in my variables above.
I basically copied and pasted from this official Shopify tutorial: https://shopify.dev/docs/apps/build/orders-fulfillment/returns-apps/build-return-management#step-6-o...
I've identified the issue. The error occurs because the return status is set to "REQUESTED." In this state, the API does not allow the removal of individual line items. You must first accept or decline the entire return request (via admin or API). Once accepted, the status changes from "REQUESTED" to "OPEN," at which point you can remove individual line items successfully.
While I've resolved the issue, I would like to suggest that the API's error message be more descriptive. Instead of stating that the "quantity is invalid," it would be much clearer if the error indicated that individual line items cannot be removed when the return is in the "REQUESTED" state. Providing this information would help quickly understand the root cause of the issue and avoid unnecessary confusion.
Additionally, it would be beneficial to have the ability to remove a single item from a return request while it is still in the "REQUESTED" state. This flexibility could enhance the user experience by allowing more granular control over return requests before they are fully processed.
I'm seeing this as well, but I'm not using the REQUESTED status. It would be nice for documentation of when a line item can be removed and can't.