draftOrderCalculate is always returning a blank list of availableShippingRates?

I’m working on a Shopify App that calls the GraphQL mutation draftOrderCalculate.

In this past we were able to pull shipping rate options from this mutation via the availableShippingRates field, but we noticed yesterday that it is always returning an empty list of options now.

It’s possible there was a change in the API, but I wasn’t able to find anything in the release notes. If there was a breaking change, I know:

  1. This code was working at least back in April 2022.
  2. It was referencing API version 2021-04, which I see is gone now.

The app’s permissions are:

['read_products', 'write_orders', 'write_draft_orders']

Our mutation looks like this:

mutation draftOrderCalculate($input: DraftOrderInput!) {
  draftOrderCalculate(input: $input) {
    calculatedDraftOrder {
      subtotalPrice
      totalPrice
      totalShippingPrice
      totalTax
      availableShippingRates {
          handle
          title
          price {
              amount
          }
      }
      taxLines {
        title
        rate
        ratePercentage
        priceSet {
          presentmentMoney {
            amount
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

With the input looking like this:

{
  "input": {
      "lineItems": [
          {
              "variantId": "gid://shopify/ProductVariant/40641593573531",
              "quantity": 1,
              "appliedDiscount": null
          }
      ],
      "shippingAddress": {
          "firstName": "Test",
          "lastName": "User",
          "address1": "1 Main St",
          "address2": "",
          "city": "Beverly Hills",
          "provinceCode": "California",
          "countryCode": "US",
          "phone": "",
          "zip": "90210"
      }
  }
}

And the relevant line in the result looks like:

"availableShippingRates": [],

Any ideas on what could be causing this?

Hey @tylerchurch ,

After some testing, I was able to return an empty “availableShippingRates” array by adding or removing a few fields from the input, as well as changing settings in the admin.

A few important points are that A. shipping rates and/or carrier service rates will need to be setup in the admin that include the shipping address, B. the shippingAddress input has to be a valid address and MailAddressInput, - though I was able to generate rates using on country code and zip fields, and C. at least one line item is included - per CalculatedDraftOrder doc here.

I didn’t see any major or breaking changes related to DraftOrders in current stable releases, but I would also suggest moving your API request forward to a stable version (2021-10 and up). I was able to generate “availableShippingRates” with simliar requests to the one shared, and would suggest confirming if rates are setup as well as testing with an API Client such as Insomnia or Postman, or the Shopify GraphiQL App to debug.

If you are still getting an empty array - don’t hesitate to log an x-request-id response header returned with the unexpected result, then connect and share with Shopify Support.

Cheers!

Thanks for the reply!

After some further digging, I found that for me the required fields seem to be “provinceCode” and “countryCode” -

The app was sending full state/province names for provinceCode instead of abbreviations, and when I fixed that the shipping rates started appearing again.

It would’ve been nice if draftOrderCalculate came back with an error instead of just blanking out the shipping rates, but oh well.