GraphQl API error when using draftOrderComplete directly after draftOrderUpdate.

GraphQl API error when using draftOrderComplete directly after draftOrderUpdate.

tech-pb
Shopify Partner
1 0 0

I am creating orders in via the admin graphql API. I am initially updating the order via the draftOrderUpdate mutation and then completing the order completion via the draftOrderComplete mutation. I am waiting for the draftOrderUpdate mutation response within a promise.all and then executing the complete step. However the order complete is failing inconsistently with the following error. 

 

 

 

userErrors:{
  message: 'This order has not finished calculating, please try again later',
  __typename: 'Shopify_UserError'
},

 

It seems like if I place a timeout of a few hundred ms after the draftOrderUpdate mutation I can for the most part stop the error from happening however this is an inconsistent solution. I was wondering why 

  1. The draftOrderUpdate mutation returns a success and the draft order object if it is in fact not finished processing.
  2. Why there needs to be a delay placed in between these 2 API calls

This seems like a potential bug in the graphql API and if this is in fact expected behaviour what is the best way to mitigate it so I don't experience this error.

 

Cheers,

 

Neil

Reply 1 (1)

Alex
Shopify Staff
1561 81 342

Hey @tech-pb.

 

This looks to be intended, and it's returned when there are background processes taking place on our end which need to complete before the draft order can be completed.

 

We're returning a success response to your update request because it did indeed succeed, but it looks like there's some post-update logic we need to perform on the draft order after the fact.

 

The delay working for the most part makes sense at that point, because eventually the background work finishes. It looks like what you should be doing is delegating completion to a retrying background job or just putting it on a retry loop every 300ms or so until it completes. I can see that this does not appear to be evident on documentation at all, but I am seeing that it is coded pretty deliberately. I'll make sure that feedback is passed on in the interest of making the documentation more clear.

 

Cheers.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog