DraftOrder API total_price racing condition: does not always reflect the actual latest pricing

tolgapaksoy
Shopify Partner
105 7 64

I have a very annoying issue with the DraftOrder API. When I apply a "shipping_line" to a DraftOrder and save it, the shipping_line will be included in the API response, but the "total_price" field will not reflect the new pricing with the shipping_line costs applied.

 

If I put a "sleep 1" and refetch the DraftOrder, the "total_price" will be updated with the actual pricing including "shipping_line" costs.

 

This is quite annoying, as we absolutely rely on Shopify API pricing, because we use the DraftOrder API in combination with Checkout API to create a more complex checkout system.

Replies 5 (5)

Busfox
Shopify Staff (Retired)
628 49 110

Hi @tolgapaksoy,

 

I'm unable to replicate this issue with my own test app and shop. Can you share an example request that you are experiencing this issue with? If you share a request id (found in the response headers), I can look at the request in our logs.

 

Thanks!

To learn more visit the Shopify Help Center or the Community Blog.

tolgapaksoy
Shopify Partner
105 7 64

@Busfox thanks for checking back.

 

I can confirm that this is still very much an issue for me.

 

Steps:

Simply creating a DraftOrder without a shipping_address, and without a shipping_line through the API.

Set a shipping_address and a shipping_line handle (an actual existent one). Save the DraftOrder.

 

The response does not contain the shipping_line handle that i just saved with. I reload the DraftOrder through the API after a second, and suddenly the shipping line is set and prices have updated.

 

Same issue when changing the shipping_line and address of an already existent DraftOrder.

 

I'm using the shopify_api Ruby gem, and not sure how to provide you with a Request ID of an update API call.

 

But I can assure you that I can 100% reproduce this every time I try to set/change a shipping_line and shipping_address of a DraftOrder.

tolgapaksoy
Shopify Partner
105 7 64

Here are two example request I just did:

 

An update of my address and shipping line: 7f88e391-abf3-4fbd-af93-73a4792824b5

It does not contain the new shipping line, but the old one.

 

After that PUT request, if I simply refetch that DraftOrder, it does contain the shipping line: 591231ee-2f19-4afc-893d-630cbaf5ae1e

Busfox
Shopify Staff (Retired)
628 49 110

Hi again,

 

It looks like the update call returned a 202 response. This means the update was accepted, but needs to be processed still. I'd say the behaviour you highlighted is in line with what should be expected with 202 response codes. Once processing has been complete, the object would have the updated details.

 

I'd recommend looking for 202 responses and fetching the resource again for the updates in cases like this.

 

Cheers

To learn more visit the Shopify Help Center or the Community Blog.

tolgapaksoy
Shopify Partner
105 7 64

Hi Busfox,

 

That explains a lot, thank you. I'm using the Shopify_api ruby gem. Is there any way that this is "baked" into the gem by default? Because it seems like it's something asynchronous, and I might not be able to rely on simply fetching the resource again instantly after updating it.