Is it possible to get the shipping rate from an order?

Esign
Shopify Expert
3 0 0

Hi,

I was wondering if it is possible to get the shipping rate id from an order. The only data that seems useful to me is the one under shipping_lines.
At the moment I collect the rate by first looking for the correct shipping zone based on, among other things, the country of the destination. And then I look at the correct rate based on the code in the shipping lines of the order. But the problem with this is when a shipping zone has rates with the same name... So I hope there are better methods, because this one is not really waterproof.

Thanks in advance!

Replies 2 (2)

Alan
Shopify Staff
129 15 24

Hi @Esign - thanks for getting in touch. I definitely understand where you're coming from here - it can be a little difficult to parse multiple IDs. At the moment, you're definitely correct that the information under shipping_lines would be the most relevant when you're querying orders. An example query you might want to take a look at would look something like this:

shippingLines(first: 5) {
        nodes {
          id
          code
          source
          title

 

This would give you a little more detail on each order's shipping rate and could better help parsing between the different ones by including the id, source and title of each one. I'd recommend following this format for sure, if you're not doing so already. 

 

At the moment this would be the best way to source this shipping rate data per order - but I hope this helps and provides some next steps for you. 

 

Cheers!

Alan | API Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog

guest4
Shopify Partner
83 6 20

@Alan@ShopifyDevSup,

Should this be taken to mean that:

 

 

{
fulfillmentOrder(id:"gid://shopify/FulfillmentOrder/1234567890"){
    order{
      shippingLine{
        code
      }
    }
  }
}

 

 

Would return the shipping line for that particular fulfillment order and not a presumably random shipping line (in the event that there are multiple fulfillment orders for the order and assuming that there would ever be more than one shipping line per order)?