Retrieving Shipping Costs via API

Highlighted
New Member
3 0 0

Hello,

As part of our store implementation, we are creating Orders through the Admin API. Our fulfillment team prints a UPS/USPS label from the Admin interface after selecting the calculated shipping rate.  That all works wonderfully. 

We're looking to capture the actual calculated shipping rate to account for our total costs.  

However, even after the order is fulfilled, the `shipping_lines` array is null.

I'm hoping this is something simple that I'm missing, or there's some super secret way to get it.  

Any ideas on how I can retrieve this data?  Thanks so much in advance.

-Matt

0 Likes
Shopify Staff
Shopify Staff
1113 77 153

Hey Matt, 

Shipping labels are not currently exposed in the Orders API endpoint, I'm afraid. Just to clarify though, is it purely the shipping label price that you're trying to access for reporting reasons? 

If so, there may be a workaround for you here via our Event API. It'll likely take some parsing in order to get the data you want programmatically, but if you were to use the event endpoint (ex. https://shop-name.myshopify.com/admin/orders/your_order_id/events.json) on an order you purchased a shipping label for, you should see a corresponding order event for that label purchase.

The event should have a 'verb' of "shipping_label_created_success" - and that event's 'message' would contain something like "You purchased a shipping label for $9.50 USD." as an example, giving you the price of the label that was purchased. 

Hope that helps! 

0 Likes
Shopify Partner
660 0 103

Hi Josh,

I just came across this post as I also need shipping cost for reporting purposes.

It would be great to add it on the order.shipping_lines[]

Also, regarding your work around. This verb is in the documentation. Is it safe to use?

And I also see no webhooks to subscribe to events? (only fulfillment events)

0 Likes
Shopify Partner
660 0 103

Now I'm wondering if I can use that endpoint to access other data not available in the 'normal' api.

Is it possible to get an exhaustive list of all verbs?

0 Likes
Shopify Partner
660 0 103

Sorry for another question but do you have a sample json for a shipping_label_created_success?

Is it attached to the shop or to an order? If it's attached to a shop then I'm wondering how we can match it with an order....

0 Likes
Shopify Partner
660 0 103

Another customer requested a report pulling shipping label costs.

Any improvement planned in this area would be very welcome!

0 Likes
Shopify Partner
660 0 103

We managed to retrieve the shipping_label_created_success event.

We can parse the string but we are reluctant to doing so because any change in the text format would break the code.

Is it possible to change the event so that the amount is added to the arguments array property?

That would prevent parsing.

https://help.shopify.com/api/reference/events/event#arguments-property

0 Likes
Shopify Partner
14 0 3

@Inspire, it is possible to get the shipping cost. And, I'm sorry Josh doesn't seem to be able of helping. Use GraphQL and retrieve:

events(first:20) {
  edges {
    node {
      message
      attributeToUser
    }
  }
}

... as part of order(). Then just parse the messages. Something like this:

 

for event in data["order"]["events"]["edges"]:
   e = event["node"]
   if(e["attributeToUser"]):
      m = e["message"]
      if "purchased a shipping label" in m:
         m = m[(m.find("$")+1):]
         endIndex = m.find(".", m.find(".")+1)
         m = m[:(endIndex)]
         deliveryCost = float(m)
      if m.isdigit():
         deliveryEstimateComment = int(m)

 

 

@Josh, in the unlikely event that you read this, and even more unlikely event that you actually care (yes, that this point I'm quite cynical given that we've been asking for this for 2+ years). Please consider exposing the shipping labels. See my full explanation of why this is needed here: https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/urgently-need-a-solution-for-downloadi...

 

 

 

0 Likes
Shopify Staff
Shopify Staff
1113 77 153

I do read this, and have been chatting with Clement directly outside of the forums. I have already logged a request to make this available outside of reading order events. 

2 Likes
Shopify Partner
660 0 103

Still no update on this issue?

We get regular requests from merchants trying to report on their shipping cost.

1 Like