Query orders by fulfillment assigned location

Hey guys !

I fetch the list of my orders through the GraphQL API.
Things are going smooth, but now I need to be able to filter my orders depending on which location they’re assigned on.

Basically I have 3 different locations where products are stocked. They’re defined on one or another location, so I am already good with the fact that buying one product make him route to the right location.
But now I need to list orders for each location, to be able to act accordingly.

I know there was a deprecated location_id before, so I tried it but without success.

Does someone has any tips ?

Thanks a lot

1 Like

Hey @scroped

Graphql does have a query filter for location id that you can use

Alternatively, if you need to get more granular and retrieve just the fulfillments for each location (in cases where a single order may have multiple locations assigned) using fulfillment orders is the best option for those:

Hope that helps.

Hey! Thanks for your quick answer.

It looks like it’s the exact thing I was looking for. But I cannot make it work for some reason. So there are a bit more informations that would help us resolving that

First, I am trying with “OPEN” orders, but in the UI of Shopify, there is the location.
When I check the network of my browser, I see a

query OrderFulfillmentOrdersQuery($orderId: ID!, $first: Int!, $after: String) {
    order(id: $orderId) {
      id
      fulfillmentOrders(
        displayable: true
        first: $first
        after: $after
        sortByFulfillmentPriority: true
      ) {
        edges {
          cursor
          node {
            id
            ...FulfillmentOrderAttributes
            __typename
          }
          __typename
        }

That returns the assignedLocation and stuff

assignedLocation {
      location {
           id: 'gid://shopify/Location/106311319881'

So now I tried stuff that you gave me in your message

query: 'location_id:gid://shopify/Location/106311319881'

or

query: 'reference_location_id:gid://shopify/Location/106311319881'

None of them returns a single order. This is my query :

orders(first: $first, sortKey: $sortKey, after: $after, query: $query) {
            edges {
                node {
                    id
                    cancelledAt
                    cancelReason
                    closed
                    closedAt
                    email
                    fulfillable
                    fulfillmentOrders(first: 25) {
                        edges {
                            node {
                                id
                                assignedLocation {
                                    location {
                                        id
                                        name
                                    }
                                    name
                                }
                            }
                        }
                    }

Some other pieces of informations that might help :
This is what I set in my client in my code

scopes: ['read_orders', 'read_assigned_fulfillment_orders'],

The app does have these authorizations
And this is api version :

apiVersion: '2025-04',

And obviously without the query, I retrieve all my orders as intended.
But for some reason, fulfillmentOrders are not returned within my query, they are always empty. Even tho as I said on the ShopifyUI it is retrieved

I am inclined to test anything !
Thanks for you time

Hey @scroped,

the Shopify Search Syntax uses the legacy resource ids in most cases.

This means in your case you should chop off the gid-part and transform gid://shopify/Location/106311319881 to 106311319881 when building your query, resulting in:

query: 'location_id:106311319881'

Hope this helps.

Kevin :hatching_chick:

Thanks Kevin!

Thanks to you both I figured this out.
The query working is

query: 'reference_location_id:106311319881'

For future readings :

query: 'location_id:106311319881'

Doesn’t work

Thanks a lot you guys !
Cheers

1 Like

Glad to see this is working now!

I just want to add one more tool you should add to your toolbox. I use our syntax debugging tool daily to help in troubleshooting! Even when no errors are returned, adding the debugging headers can give you an idea of how the query was parsed.
Search Syntax Debugging

1 Like