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.
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.
… 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)
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.
Seems to be crickets from Shopify on this one, and now I’m stuck as a result as well as all the rest of the community. This is basic stuff in a platform! We are dying without this ability to easily retrieve our data.
Status? Anything? Is it coming or is it a dead topic to Shopify?
@LukeG the code below is a little snippet of C# that is getthing the rates back for me. This one threw me because I wasn’t getting the value for every shipped order. When I dug into it I found there are actually two that can get recorded. Let’s hope not three
DataRow rows = eventsDS.Tables[“events”].Select(“verb = ‘shipping_label_created_success’ or verb = ‘external_shipping_label_created_success’”);