Graphql shopify query to pull orders for products from specific location

sdp1016
New Member
3 0 0

Hello:

I need to generate a list of orders, within the past of x-minute(s), that contain products from a specific location.  One solution is to use the orders webhook, and have to open each payload and review all orders.  I was hoping to use graphql to query for the exact response I need.  The issue is that I can't seem to work out the code, and was wondering if anyone else has accomplished this. 

base graphql call to https://<<store>>/admin/api/2020-10/graphql.json:

query {
  orders(first:10) {
    edges {
      node {
        id
        name
        displayFulfillmentStatus
        channel{
            id
            name
        }
        lineItems(first:50){
            edges {
                node {
                id
                title
                }
            }
        }
      }
    }
  }
}

 

I have tried to add in criteria to the lineItems, but have not been successful.  Any help is appreciated.

Best regards,

sdp

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 220

While drilling so far down into the GQL query I'm not sure if you can pass along query restrictions to only pull order line items for just a specific fulfillment location. But you can determine each order line item's fulfillment site within the query. Iterating through these in your code you can "do things" to just the one site you are looking for. Does this help? Example below.

 

{
  orders(first: 5, reverse: true) {
    edges {
      node {
        id
        name
        displayFulfillmentStatus
        channel {
          id
          name
        }
        lineItems(first: 50) {
          edges {
            node {
              id
              title
              fulfillmentService {
                id
                location {
                  id
                  name
                }
              }
            }
          }
        }
      }
    }
  }
}

 

sdp1016
New Member
3 0 0

Thank you Greg.  I was hoping to avoid having to go through each order to decide what orders need to be processed.  Hence the attempt at a graphql solution.  In the past I have used webhooks, orders/create, and unpacked the json to verify if an order needs processing.  It results in may orders unpacked that do not require processing.  I was really just hoping to be able to pull orders given a set of products.  The product list could be quite extensive, so I was hoping that the location would do the trick.  In the end, I wanted to avoid unpacking/reviewing 100 or 1000 orders to only need to process 5 or 50.  At least the message size returned by the graphql call is smaller than the payload sent by the webhook. 

 

0 Likes