Get Location Id of the item on the order that shopify used, via the shopify order API

Donald_Carter
Shopify Partner
1 0 3

Hi,

I am using the Shopify REST API to retrieve order information (...admin/orders.json?).  A client has 2 locations that might stock inventory.  From the retrieve order API, how do I know which location the item was allocated from?  the "origin_location" field has a value that is the same for all orders, although the allocation was from different locations for different orders.  the "origin_location" id value is also not a location id value.  the "location_id" field has a value of "null". the "fulfillment_service":"manual" and "variant_inventory_management":"shopify" if that is important.

 

Thank You.

Replies 17 (17)
Josh
Shopify Staff
Shopify Staff
1134 82 213

Hey Donald, 

 

I wanted to touch on the 'location_id' on an order that you had mentioned, that location_id will only be populated when the order was placed through Shopify's Point of Sale system. On any other order that field will be null. 

 

For other orders that are placed, we'll temporarily take inventory from a location based on the shop's fulfillment priority settings. But those settings cannot be fetched with the API currently. Regardless of where we temporarily take the stock from though, you can still follow our guide here and create a fulfillment with any location that an item has been stocked at, and we will take inventory from that location instead. So ultimately, you can be the source of truth in this situation and you get to choose whichever location you want, provided that the item you're fulfilling has inventory there. 

Josh | 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 the Shopify Help Center or the Shopify Blog

MHolt
Tourist
9 0 5

This would be helpful, or at least when you fulfill something let us know in the response if inventory was restocked somewhere else because the allocation location did not match the fulfillment location. What happens is when you fulfill from the correct location you end up adding stock back to the other location, which may allow overselling from the other location if you are not syncing that location as well and are only controlling inventory for the location you are fulfilling from.

J_Douglas_Cryer
Shopify Partner
4 0 9

Whilst the original question was answered there appears to be no solution at present.  Without knowing, by item where a piece was allocated from it does not seem possible to to make a decision about where to send the order item fulfilment to.

 

Our client has a main warehouse where all orders are sent for fulfilment and a store which is set up as a stock location from which they can fulfil orders.  Currently the warehouse has to refer all short picks to see if the store can handle them.  We would like to know when we read the order those items that Shopify has decided to fulfil from non warehouse locations in order that we do not bother the warehouse with them.  We could then re-direct the other part of the order to the chosen fulfilment location.

 

It seems like this functionality falls short of a usable solution, unless I am missing something.

 

Is it perhaps to do with the new fulfillment_order resource?

nbourdeau
New Member
1 0 2

Hi

This seems to be a recurrent problem ... has this been addressed yet in the API ?

We are using the API to automate shipping for our customers and we need to determine the "pickup" address based on the selected location ...

 

OneSource
New Member
1 0 0

We ended up using custom fulfillment locations.

You can add one here admin/settings/shipping/accounts_and_integrations

Then that will show up at your admin/settings/locations page so you can get the location id from there.

Make sure you put your inventory into those locations.

Then on the orders you will see by line item a field called fulfillment_service which will have the name of your location if inventory was pulled from your custom fulfillment location.

Lasvad
Excursionist
14 0 4

Definitely a viable solution for some cases.

One issue I found with customer fulfillment locations is when using them for a product, you cannot have inventory/fulfill from any of your shops locations. For a product, one can only have Shopify locations OR customer fulfillment locations, not a mix. 

How the custom fulfillment location shows up in the JSON payload as the name of the customer fulfillment works. If there was a way to have the Shopify locations show up that way, we could find the Shopify location Id that is needed for creating fulfillments via API by matching the name with one of the Shopify locations names. 

Ideally tho, the Shopify location Id that is assigned to the unfulfilled order would be added to the json payload to remove the need to search by name. 

JoesIdeas
Shopify Expert
1669 143 428

+1 on this question.

I couldn't find a way to get the location of a line item if the line item has stock at multiple locations.

What a bummer, that's good data... sucks letting clients down because of lack of data.

Shopify, I think the best solution would be to add a location_id property in line_items of the Order object.

Or if that's too hard, allow us to get Fulfillment priority via API (there's a hacky workaround you can do but it won't work because the Inventory Levels API does not return locations in their order of priority).

 

• Creator of Order Automator (automation app to save you and your team time on admin tasks)
• Shopify developer for +10 years
• Contributor on the Speed Boostr blog
• Guy who likes to help people
tjbartram
New Member
4 0 0

The answer is GraphQL.  We have had to move over to GraphQL to tackle some of the newer areas of Shopify like order item stock allocations.  We have ended up with 80% GraphQL and 20% classic API solution.  It was a relatively hard transition but it has also helped with some call limit issues.

JoesIdeas
Shopify Expert
1669 143 428

Thanks @tjbartram for the suggestion, do you have a link to the resource that allows you to get the location ID that Shopify assigns to the order line item? I looked around but couldn't find it.

• Creator of Order Automator (automation app to save you and your team time on admin tasks)
• Shopify developer for +10 years
• Contributor on the Speed Boostr blog
• Guy who likes to help people
reyanshmishra
Tourist
3 0 1

Even I am having the same problem +1 for this feature.

BogdanM
Shopify Partner
119 3 25

+1 for this feature.

I couldn't find a way to get it with GraphQL either.
Using the draftFulfillments mentioned in other posts proved to be useless as it is always returning the default location.

 

Bogdan | WebShopAssist
User friendly apps with top-rated support
- SKUGen the SKU generator
- DPD Integration
tjbartram
New Member
4 0 0

Hi @JoesIdeas 

I used the Fulfillment Orders resource, which you can obtain via the Order endpoint.

This gives you a collection of lineItems and the location from which they should be fulfilled. 

Greg_Kujawa
Shopify Partner
1020 83 262

This is definitely possible via the GraphQL API. Here is an example, where I pull the 10 most recent orders. Each order's first 10 line items are iterated, with each item's fulfillable location ID and name listed. 

I've found that some things that are either not doable via the REST API or else would require multiple steps are usually worth checking out in the GraphQL API. After you get used to the seemingly strange syntax it's not that bad!

{
  orders(first: 10, reverse: true) {
    edges {
      node {
        id
        name
        createdAt
        lineItems(first: 10) {
          edges {
            node
            {
              id
              originalUnitPriceSet {
                presentmentMoney {
                  amount
                  currencyCode
                }
              }
              discountedUnitPriceSet {
                presentmentMoney {
                  amount
                  currencyCode
                }
              }
              quantity
              product {
                id
                title                
              }
              fulfillmentService {
                location {
                  id
                  name
                }
              }
            }
          }
        }
      }
    }
  }
}

 

HedzerG
Shopify Partner
1 0 0

+1 on this question.

indeed - the solution would be location_id in orderlines and you can manage the locations

velval
Tourist
3 0 2

In order to get the location_id you will need to make another API call to GET https://{shop}.myshopify.com/admin/api/2021-10/orders/{order_rest_id}/fulfillment_orders.json

This will return the location_id for the line items of the given order_id. See a better explanation here: https://community.shopify.com/c/shopify-apis-and-sdks/how-to-get-order-item-location-through-order-a...

Rajnahar
New Member
2 0 0

 Hello all,

 

I have the same challenge as mentioned here. How can I get the location id of the item in an order? I have multiple locations and they can have the same styles. Though we have set the preferred location in Shopify settings, how do we get the location id allotted by Shopify into our systems? We use REST API.