Determine which location to use for a fulfillment through the API when stock is tracked by Shopify

Excursionist
17 0 12

Silly me, it was API permissions, now working. Thank you so much!

0 Likes
Shopify Partner
134 4 14

I was happy to find this topic, and tried the graphql query, but it doesn't seem to work as expected.

 

I have an unfulfilled order, where the fullfilment location in the shopify admin is showing LOCATION2 the other location (1,3,4) don't have any inventory for this product, so it's correct for shopify to display LOCATION2

 

but when I get this order with the graphql query, I get location1, and when I add the parameter hasActiveInventory it returns true, although the product really is out of stock there?

 

the graphql query I'm using:

{
    order(id: "gid://shopify/Order/1056366723152") {
      draftFulfillments {
        lineItems {
          id
          fulfillableQuantity
        }
        service {
          location {
            id
            name
            hasActiveInventory
          }
        }
      }
    }
}
0 Likes
Shopify Partner
134 4 14

edit: - doublepost

0 Likes
Tourist
6 0 3

Any chance you have changed the location from the admin panel?  What I'm seeing is that the same location comes back for the draft fulfillment no matter what I change the location to from the admin panel.  Seems like a bug - either it's always reporting the original location or the primary location.

0 Likes
Shopify Partner
134 4 14

no, I didn't touch the order at all, as a matter of fact, it shows LOCATION2 because that's the only one with that particular item in stock, but somehow the API just shows the primary fullfilment location...

 

I now resorted to doing the fullfilment logic myself (which is probably better, since i want to split product fullfillments when I have an order of 2 product X and one location doesn't have 2 of those in stock. shopify will just fulfill it and set your primary location with a -1 inventory, but keep the 1 inventory in the other location, I want it to split the lineitem into 2 fulfillments.)

 

 

this is the graphql query to get my orders lineitems and available inventory for the lineitem product:

 

 query {
    order(id: "gid://shopify/Order/$orderId") {
        lineItems (first:25){
          edges{
            node{
             id
        	variant{
        	id
        		inventoryItem {
        		id
        		inventoryLevels(first:15){
                edges{
                  node{
                    available
                    location{
                      id
                      name
                      fulfillsOnlineOrders
                    }
                  }
                }
              }
             }
            }
        }
      }
    }
  }
}

 

0 Likes
Tourist
6 0 3

Just did some testing, and I can confirm that the location in draftFulfillments is always the location that is set as the "shipping origin".  Again, this feels like a bug.

 

With respect to your query - I think that will certainly help you build your own logic, just keep in mind that until your items ship, there will still be inventory reserved from whatever location Shopify picks via its own priority algorithm.  Once your items ship and the fulfillment is created, Shopify will adjust accordingly.

 

I have yet to find an API that allows one to change the intended fulfillment location - like you can do via the UI.

1 Like
Highlighted
Shopify Partner
134 4 14

You are correct, this raises the next issue. Shopify reserves inventory on a location and we have no idea which location it is subtracted from :( so when you have 

 

Product X

location_A 1 in stock

location_B 1 in stock

 

an order gets placed, for 1x product X, shopify subtracts the inventory, my app wants to fulfill this product, and retreives location inventory information:
Product X

location_A 0 in stock

location_B 1 in stock

 

my app fulfills from location_B because my app thinks that is the only one with inventory.

 

then after this the inventory looks like this:

Product_X

location_A 1 in stock (because shopify released the reservation)

location_B 0 in stock

 

We have no clue where the inventory gets reserved, shopify needs to address this, so we know from wich location to fulfill.

0 Likes
Shopify Partner
134 4 14

I had a mail exchange with shopify development team, here is some more information,

tldr; it's currently not possible to get the correct fulfillment location through the API

 

 

Currently it isn't possible to determine which location an orders line items 
have been assigned to other than in the admin. It is left up to fulfillment providers to chose
which location to fulfill an order from and the stock will be adjust accordingly. We are looking to introduce a location origin feature when we release our Fulfillment API update in July
to help determine which location Shopify has assigned a line item to. I hope this helps build some context Tom, if you have any other questions please do not hesitate to ask!
Thanks for your reply, well that’s exactly the issue I’m describing😊

It would be great if you could add that in the API in July 
since the admin sees the selected location as well, it would be nice the API could see it to) So, what’s the draftFulfillment field for in the graphql API, is it not yet ready to use? Also it’s not great for fulfillment providers that stock has been subtracted (reserved)
for an order prior to fulfillment, since many items at my customers store are currently low in inventory.
It means I just cant fulfill the items through the API because when shopify Already subtracted the stock
from Location_A my app will look for the next location where it is available,
and fulfill it from let’s say location_B after my fulfillment then shopify release the reservation on location_A,
which means it’s in stock again on location A…. very confusing

 

I completely understand the limitations you're experiencing, I'd stay tuned to our API announcements 
for the Fulfillment API updates in July. Currently the draftFulfillment API will only provide the line items primary location,
not the location the order was assigned to. Hope that helps clarify!

 

 

0 Likes
New Member
2 0 0

Hi Josh, I wanted to check if you know whether there have been any updates on this topic? I am experiencing the same issue as Evelyn. Here's a description of the issue: 

The basic question is, is there a way that we would be able to use the shopify rest API to determine the location_id that an order_item is supposed to ship from? I work with a 3PL fulfillment company and we use a private app to connect to our customer's shopify account, to pull orders and confirm fulfillments. One of our customers has multiple 3PL partners, and they can have orders which have some items shipping from us and other items shipping from another 3PL. So we need a way to determine which 3PL (shopify location) an item is supposed to ship from. 

 

Shopify allows you to track inventory by multiple warehouse locations in shopify, and then also show you in the order detail which location they temporarily assigned a given order item to ship from. And when you mark an order as fulfilled, you have to say which location_id you shipped it from so that shopify can adjust inventory accordingly. However, the big problem is that while shopify temporarily assigned an order item to a given location, they do not expose this data to anyone in their API from what I can see. The order data does not have item level locations, so we cannot know where the item should ship from.

 

This would not be a problem if we were the only fulfillment company, because we can assume all fulfillable items should be fulfilled by us and we can then choose the correct warehouse to ship from ourselves (if you had inventory in multiple Excelsior warehouses). But while our customer is still fulfilling orders from multiple 3PLs, we need to be careful not to ship orders/items that they also are shipping.

 

Thanks!

Chris

0 Likes
Shopify Partner
134 4 14
Unfortunately there is still no way to do this as far as I’m aware :( even if you have multiple locations yourself you can’t know where the inventory has been taken from by Shopify, unless you save all product data externally and compare the inventory from before the order and after, to see where Shopify subtracted the item from which seems really complicated for something so simple..
0 Likes