Hi Shopify team,
I’m developing a CarrierService service to provide shipping rate for our Shopify store, I searched the documentations and didn’t find any info about how to respond in case there’re errors on the shipping service side.
I’d be appreciate if you guys can help me with this problem.
Thanks,
Huan.
Hey @huancao3001 ,
This is a great question and a good call out to add this to our documentation.
If there are errors on the shipping service side and you’re unable to provide rates, the best way to handle that is to respond with an HTTP response code that is not in the range of 200..300. For example, a regular 404 will do.
Depending on the reason for not returning rates, for example if it’s taking too long to handle the request; one way to handle that is to send prepare_rates requests ahead of time (ie while a customer is still in the cart). This should cache the result, leading to faster times at checkout if the request is identical.
Documentation on that here: https://shopify.dev/docs/api/ajax/reference/cart#example-prepare_shipping_rates-call
Hope that helps!
Hi Kyle @ShopifyDevSup ,
Will Shopify do anything with the error response? I tried returning the 404 Not found error code but Shopify didn’t seem to do anything with it. Should I include any data/value/message in the response’s body?
Thank you,
Huan.
Hey @huancao3001 ,
When you send the 404, what happens is that will trigger the backup rates immediately. We don’t currently have anywhere in the admin or API responses where that would be returned, but including a message in the response body could still be useful. The reason for that is if you end up with an issue with your shipping, we would be able to see your response in our logs to get more context on the reason the rates were not returned.
Just one thought here as well, since it sounds like this is for your own store, once the order is complete, if you’re able to associate the 404 with a specific order, you could use something like the orderUpdate mutation to add a note or tag to the order to give your team more context on why the carrier service rates weren’t used.
Hope that helps
Hi again @huancao3001 ,
Just updating the thread here for anyone else who may have similar questions, we’ve updated our documentation to include steps on how to return error responses. You can view that here: https://shopify.dev/docs/api/admin-graphql/2024-01/queries/carrierService#:~:text=still%20be%20valid.-,special%20conditions,-To%20indicate%20that