Storefront api not return third party shipping rates on cart

The storefront api does not return third party rates on a cart. If a shipping profile is configured with third party rates as well as flat rates, the flat rates will be returned by the storefront api, just not the third party rates.

If anyone from the Shopify side is able to share their insight, I am wondering if this is a bug or the expected behaviour?

Hi Garret,

It’s possible this may be intended - third-party shipping rates may be outside the scope of the Storefront API. It may instead be possible to store the rates as metafields instead and use the Admin API to access them?

Thanks for your response @Liam-Shopify. If the store ships globally I think it would be too much data to store in a metafield.

The /{locale}/cart/shipping_rates.json endpoint in the Cart API returns third party shipping rates, but I am not able to use it in this situation because it only provides rates for the cart id stored in the browser cookies.

If that endpoint is, I don’t see why the Storefront api wouldn’t. Is it possible to get a more concrete answer on if it is expected or a bug?

Found the answer. You need to use the withCarrierRates argument on the deliveryGroups connection. More here.

Your price plan also has an effect

To use third-party carrier-calculated shipping, you must be on the Shopify Advanced or Shopify Plus plan. If you’re currently on the Shopify plan, then you can opt for the monthly fee to add this feature or switch to yearly billing. Third-party carrier-calculated shipping isn’t available on the Basic Shopify or Shopify Starter plans.

From here.

1 Like

Thanks for coming back to update this topic Garret & glad you found an answer!

Hello,
I’m still unable to get the results even after using deliveryGroups,
Do you mind sharing the call you used?

Thanks

@Mehdi The store you are testing on is on a price plan that allows access to the rates?I found that dev shops were not excluded from this requirement

Hi, Yes I requested to add the feature on the store, I paid around 20$ extra for it.

This is the code I’m using.

First call to prepare shipping rates:

const prepareResponse = await fetch(`/cart/prepare_shipping_rates.json?shipping_address[country]=${encodeURIComponent(country)}${provinceParam}&shipping_address[zip]=${encodeURIComponent(zip)}&include_carrier_rates=true`, {
    method: "POST",
    headers: { 
        "Content-Type": "application/json",
        "X-Requested-With": "XMLHttpRequest"
    }
});

Then polling call to get the rates:

const response = await fetch(`/cart/async_shipping_rates.json?shipping_address[country]=${encodeURIComponent(country)}${provinceParam}&shipping_address[zip]=${encodeURIComponent(zip)}&include_carrier_rates=true`, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'X-Requested-With': 'XMLHttpRequest'
    }
});

I was using the graphQL storefront api. See here Cart - Storefront API

Not sure about this other one you shared