I have found a potential bug where the the GraphQL order edit API doesn’t perform the same between two otherwise identical orders, one placed through the online store and one placed through draft orders.
I am using the order edit API to remove an item with a particular discount and then add the same product to the order again without that discount.
With an order placed through the online store this works as you would expect, the item with the discount is removed with the orderEditSetQuantity mutation and the same product is added through the orderEditAddVariant mutation.
Running the same process on a order created and through draft orders gives the following error message:
X was not added because it's already on the order
Editing the order through the admin manually does let you do this too, so it’s only effecting draft orders through the API.
I can provide order ID’s to Shopify staff if needed.
Order of requests:
orderEditBegin to initiate the order edit.
orderEditSetQuantity to set the quantity to 0, removing it from the order.
orderEditAddVariant to add the same product again.
orderEditCommit to commit the changes.
API versions I have tried (same result on all):
2021-01
2021-04
2021-10
2022-01
Other things I have tried:
Using orderEditSetQuantity to add quantity back to a removed item within the same transaction results in the error There must be at least one change to be made. when trying to commit.
Using orderEditSetQuantity to add quantity back to a removed item in a separate transaction resulted in the error: The line item cannot be edited because it's either fulfilled, removed, related to a tip or selling plan.
Thanks for taking the time to post, I had a look through the details shared. While we can’t provide authenticated support (access store or partner related info) through these forums, we can take a look into logs where errors or unexpected behaviours are being returned.
Could you replicate a few of the requests and log an x-request-id header value returned with unexpected results: orderEditSetQuantity, orderEditCommit, and orderEditRemoveLineItemDiscount.
Additionally, an example of the error on orderEditRemoveLineItemDiscount would be insightful, as would an example input and GraphQL body being used that is generating the error.
Do you know if there is a way to get response headers/ID when using the ShopifyApp gem? I can’t see anything obvious in the documentation, the response object (GraphQL::Client::Response) doesn’t seem to contain them.
Thanks for getting back to me here. I’m not personally a Rails developer, and a bit unfamiliar with some of the intricacies of developing using the shopify_app gem, including setup of client and logging configurations - potentially a question better served through the Shopify/shopify-app - GitHub Repo.
To circle back on the behavior mentioned in your original post, I did take some time to do some testing in a few different ways, but ultimately was unable to replicate.
I initially tested with my node.js app, however when debugging I’ll usually default to double checking requests using an API Client such as Insomnia. This allows for pinpoint testing of specific API calls, rules out potential configuration issues, and most importantly offers quick access to request details (body, headers, etc).
If you are able to figure out logging in your app or replicate in an API client, please pass on x-request-id headers for the related requests and I can absolutely take a closer look.
Thanks for the reply again. I’m currently waiting for my client to sign-off some more time for me to investigate this on their behalf. I’ll let you know if I get that and come up with anything.
To circle back on the behavior mentioned in your original post, I did take some time to do some testing in a few different ways, but ultimately was unable to replicate.
If I get time I will try this again but without use of the gem and see what that results in. It could be an issue with the gem in some way, at least that is what I am starting to think. Would be weird as I can’t imagine it deals with draft orders and online orders differently when it comes to the API though, but you never know!