A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am using the GraphQL API to cancel orders on Shopify. The first time I call the API with all valid mutations, it returns a job field with done as false and a job ID. However, when I make a second call to the same API, it returns an error stating "Cannot cancel a paid and fulfilled order." The first call successfully canceled the order, so I'm confused about why this error occurred on the second call. Additionally, is it not possible to retrieve the data on the same call when a job is returned, as the subsequent query for the job ID returns null in the query field because of which I am bound to make another call for the job id to fetch the data of order? Any clarification on these issues would be greatly appreciated.
Solved! Go to the solution
This is an accepted solution.
Hey @mansikumari ,
Thanks for sharing that! I can see how that error message would be confusing and would be better suited for an open order than a cancelled order. I'm able to replicate that as well so I'll pass that on that feedback to the product teams.
As for getting data on the same call, the query field does only return when the job is done.
One option is a second query for the order details. Alternatively (and possibly more efficient) the orders/cancelled webhook will return once it's complete and the payload will have the order details: https://shopify.dev/docs/api/admin-rest/2024-01/resources/webhook#event-topics-orders-cancelled
Hopefully that helps:
- Kyle G.
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
Hey @mansikumari ,
For context, the mutations that return a job ID are typically jobs that are completed Async.
The expected behaviour here would be to poll the job ID for when it has been successfully completed. https://shopify.dev/docs/api/admin-graphql/2024-04/queries/job
What's likely happening here is that the job is completing before the second cancellation mutation resulting in the error you're seeing as the cancelled order is already cancelled.
Hope that helps,
- Kyle G.
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
Hey Kyle G.,
Thank you for your response and the clarification provided.
Based on your explanation, it seems that the job for canceling the order is completing before the second cancellation mutation is processed. This results in the error "Cannot cancel a paid and fulfilled order" because the order has already been canceled by the first mutation when the second call is made.
However, I am still unclear about why this error occurs when hitting the same call again with the same order ID. My understanding was that if the order was already canceled, the second call should not result in an error but rather return a confirmation that the order is already canceled. Could you please provide further clarification on this aspect?
Additionally, I would like to know if there is a way to retrieve the data on the same call when a job is returned, as the subsequent query for the job ID returns null in the query field. Is there a method to fetch the data of the order without having to make another call for the job ID?
Your insights on these points would be greatly appreciated. Thank you.
- Mansi Kumari
This is an accepted solution.
Hey @mansikumari ,
Thanks for sharing that! I can see how that error message would be confusing and would be better suited for an open order than a cancelled order. I'm able to replicate that as well so I'll pass that on that feedback to the product teams.
As for getting data on the same call, the query field does only return when the job is done.
One option is a second query for the order details. Alternatively (and possibly more efficient) the orders/cancelled webhook will return once it's complete and the payload will have the order details: https://shopify.dev/docs/api/admin-rest/2024-01/resources/webhook#event-topics-orders-cancelled
Hopefully that helps:
- Kyle G.
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
Thanks @ShopifyDevSup Kyle G. for considering this concern and providing me with a helpful response.
- Mansi Kumari