Order edit API not performing consistently between orders placed through different channels (bug?)

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:

  1. orderEditBegin to initiate the order edit.
  2. orderEditSetQuantity to set the quantity to 0, removing it from the order.
  3. orderEditAddVariant to add the same product again.
  4. 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.
  • Using orderEditRemoveLineItemDiscount instead of this process. I don’t have the error message to hand but as the documentation says this won’t work as the line item discount has to be applied as part of an edit: Removes a line item discount that was applied as part of an order edit.

Is there anything I might be doing wrong here? If not is this something that can be fixed?

Thanks,

Andrew

Hey @Andrew-W ,

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.

I’ll keep an eye out for more details - Cheers!

Hi @awwdam

Thanks for the reply!

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,

Andrew

Hey Andrew,

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.

  • Cheers.

Hi @awwdam ,

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!

Thanks,

Andrew

Hi @awwdam ,

I got some time signed off to look into this. I’ve tested my mutations with Insomnia and I get the same error.

Request ID’s:

  1. orderEditBegin - da291a51-8c01-4ec0-9e86-55cb97f00f45
  2. orderEditSetQuantity - b8ef089e-6554-4ed4-9c04-a09b041ed0af
  3. orderEditAddVariant - b5d6ab38-13b1-48e6-a132-299da3e25def

The first two work as expected, the third returns the error. As before, only seems to effect draft orders.

If you could let me know your findings that would be great.

I have a GitHub repo with the Insomnia requests in it if you would it shared with you (contains API token so I can’t make it public) just let me know.

Thanks,

Andrew