Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to get Order Item Location through Order API

How to get Order Item Location through Order API

Ram_Kumar
Shopify Partner
17 0 4

Hello,

 

How can i get the Order inventory item location to be allocated for the order.

 

I have 2 location in my store. 

 

1) NPF Warehouse

2) Kamarajar Salai

 

My below order is allocated in Kamarajar Salai Location.

 

shop.PNG

 

Test003 Product in both my warehouses.

shop3.PNG

 

How can i get this Location in Order API. So that i can send the order to that particular allocated location to fulfill order.

 

When i try to get inventory location using below API, Item shown in both my locations.

/admin/api/2019-10/locations/26812946/inventory_levels.json

This will ship my order in both my locations. 

 

shop.PNG

 

I need Order Allocated item location, what is the usage of showing Location Name in the Front end. I hope this is a bug in shopify API.

 

Please reply asap or give any solution to fix. 

 

Thanks

 

 

Replies 15 (15)

Ram_Kumar
Shopify Partner
17 0 4

Hi Team,

 

Please check my request, Is any way to help you get this ?

 

Can we get Order Item Allocated location before Fulfillment of an order ?  same like you shown in Shopify UI ?

 

Thanks for your help

hassain
Shopify Staff (Retired)
624 104 189

Hi @Ram_Kumar ,

 

The Orders resource of the REST Admin API does not keep a reference to the location the order will be fulfilled from (e.g. Kamarajar Salai). The "locations_id" field on the Orders resource is meant to track the physical location in which the order was purchased from. Due to this, this field is only populated when the order is purchased via Shopify POS - for all online store orders this field will be `null`.

 

In order to get the location this order will be fulfilled from via the API, you need to use the FulfillmentOrder resource: https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillmentorder#index-20... . The FulfillmentOrder resource represents either an item or a group of items in an order that are to be fulfilled from the same location. There can be more than one fulfillment order for an order at a given location. Within the FulfillmentOrder resource, the "assigned_location_id"  and the "assigned_location" fields should give you the information you are looking for.

 

Here is the sample API request to get all of the FulfillmentOrders associated with an order on your store: GET https://{store-name}.myshopify.com/admin/api/2020-01/orders/{order-id}/fulfillment_orders.json. To access this data, your app may need the following access scopes: read_assigned_fulfillment_orders, read_merchant_managed_fulfillment_orders, read_third_party_fulfillment_orders (https://shopify.dev/tutorials/manage-fulfillments-with-fulfillment-and-fulfillmentorder-resources)

 

To learn more visit the Shopify Help Center or the Community Blog.

Mark_
Tourist
5 0 2

I've setup a development store with 2 locations where I'm making test orders. Looking at the orders in admin I can see it is assigning locations to orders depending on where the inventory is located. I'm using the GraphQL API BTW. Orders that haven't been fulfilled have draftFulfillments but draftFulfillments doesn't have a location field. When I mark the order as fulfilled the order has fulfillments which has a location field. How do I get the location of an order before it has been marked fulfilled? Orders never seem to have fulfillmentOrders. What's the difference between fulfillments and fulfilment orders?

Mark_
Tourist
5 0 2

Following on from my previous post above - the reason fulfillmentOrders wasn't showing up for me was because "Merchant managed fulfillment orders" permission wasn't set.  So you can now get the assigned location in fulfillmentOrders before the order is fulfilled.

gorodezkiy
Shopify Partner
6 0 20

Following on from my previous post above - the reason fulfillmentOrders wasn't showing up for me was because "Merchant managed fulfillment orders" permission wasn't set

Wow, that was surprising! Thank you for the advice @Mark_ 

First I thought that the `read_assigned_fulfillment_orders` permission should be enough, but the response stayed empty until `read_merchant_managed_fulfillment_orders` was not set 

YIK
Visitor
3 0 0

Mark_

So it means that for very Shopify Order we have to make 2 calls - the 1st one to get the order content and the 2nd one - to populate locations the items will be shipped from.

We are using REST API, so we can get 100 orders in one request - and then we would need to make 100(!) more requests to populate locations? Doesn't seem logical to me.

Just imagine Black Friday... our clients are downloading few thousand orders... how long is it gong to take? And GraphQL isn't any better in that regard.

The information is available during the order download - why not to provide it? Any suggestions how to avoid extra thousands of calls?

Thank you!

 

YIK
Visitor
3 0 0

@Mark_  Please see above. Any help would be greatly appreciated. @hassain 

Mark_
Tourist
5 0 2

@YIK I haven't done Shopify development in a while. All I can suggest is you use the GraphQL API as you will have less requests compared to the REST one.

YIK
Visitor
3 0 0

@Mark_  Appreciate the quick reply. Unfortunately fulfillmentOrder endpoint in both REST and GraphQL requires one call per order which creates a problem with performance when we deal with thousands of orders. I don't know if there's a meaningful difference in performance between REST and GraphQL, but it looks like I am stuck with one call per order either way. Thank you again!

Filljoy
Shopify Partner
211 10 67

@YIK can you instead use an order webhook to be notified of the order coming in (which includes the order body), and THEN do the GraphQL query from your end to get the fulfillable location ID? This is what I do, it's not ideal (and note that you also need to put in a 30 second delay between when the webhook comes in and when the actual order details are available on the API), but it seems to work. 

AliAdhami
Shopify Partner
4 0 0

Thanks!

bholtzclaw
Visitor
2 0 3

If you are on Shopify Plus and have access to Flow - been experimenting with a Flow rule to check fulfillments/assigned_location when the Order is created, and add an order tag (which DOES show up in the Order JSON) matching the location name. It seems to work but obviously would be an issue when fulfilling a single multi-item order from two different locations, open to suggestions here though...is there any way to add tags or notes at the item level of an order that will show up in the Order JSON?

 

I still think its a little crazy that this information is displayed at the item level in the Admin but isn't in the API - given how relatively straightforward it is to fetch this information using Flow

arlogb
Shopify Partner
1 0 0

Interesting solution to this @bholtzclaw .

 

Thought I'd chime in and also support the idea that this information should really be added to the `orders` endpoint / be available on an order object over a webhook.

 

@YIK is absolutely right that the current solution effectively doubles the number of requests required, and even if retrieving orders over webhooks, it's very possible a busy store will hit the API limit when having to verify the location for each order.

 

@hassain - could you please comment on this issue and provide thoughts/feedback on this point to the API team?

lumberbeard
Visitor
2 0 0

I'm trying to replicate what you've said here by creating a shopify flow that looks like the following:
Trigger Order Created -> Get fulfillment order data -> Add order tags

 

However, not seeing how to check the specific fulfillment (or not seeing it) for the assigned location. Is there any way you could show your flow for those of us 2 years later trying to get this functionality to work that should have been standard?!  (Thanks shopify...)

EDIT:  I figured it out for anyone else who seeks clarity for a solution to this.

 

I set the 'get fulfillment order data step to return 1 row descending. However, one of our use-cases is when we have orders that have line items coming from multiple locations. Not sure how to solve for that...  I'm thinking of using SplitOrder shopify add-on to split the order into multiple orders for each ship-from location then either add a tag or better yet a metafield populated with the location on the order record.

 

This way I can properly automate the downstream of this into other applications such as Netsuite.

 

lumberbeard_0-1709068348301.png

 

karim74
Visitor
2 0 0

where you able to solve this issue?