GraphQL pagination not working with filtered query

Solved
TomSmith
New Member
3 0 0

Hi 

Using the graphql api, i want to get all the orders which are open and not fulfilled. After searching in community i finally figured out that this query might work:

query GetShopOpenOrders($numOrders: Int!) {
  orders(first: $numOrders, query: "status:open AND -fulfillment_status:shipped") {
    pageInfo {
      hasNextPage
    }
    edges {
      cursor
      node {
        name
      }
    }
  }
}

when setting the numOrders value to something like 20, i get no results but hasNextPage is true:

data": {
    "orders": {
      "pageInfo": {
        "hasNextPage": true
      },
      "edges": []
    }

Increasing the numbers leads to returning some orders.

I thought that it would first filter the results and after that limit the number of returned orders, but it seems to be reverse.

How can i get the orders when hasNextPage is true but there is no edges returned to get the cursor to paginate? (I don't want to increase the limit number because the actual query is more complicated and I don't want to reach the limits)

0 Likes
GrahamS
Shopify Staff
Shopify Staff
47 8 2

Hey @TomSmith !

You're running into issues here as "shipped" is not a value that can be passed as part of the query. You'll want to try something like:

query GetShopOpenOrders($numOrders: Int!) {
  orders(first: $numOrders, query:"status:open fulfillment_status:fulfilled") {
    pageInfo {
      hasNextPage
    }
    edges {
      cursor
      node {
        name
      }
    }
  }
}

 

Valid values that can be passed are defined at the top of THIS DOC

Hope this helps!

Graham S | API Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
TomSmith
New Member
3 0 0

Hello @GrahamS

Thanks for your response. I have already tried "fulfilled" but it doesn't work. As you can see in these community topics:

https://community.shopify.com/c/Shopify-APIs-SDKs/Shopify-Admin-Graphql-API-Order-Search-Query-Synta...

https://community.shopify.com/c/Shopify-APIs-SDKs/How-can-I-get-all-orders-by-admin-orders-json-filt...

https://community.shopify.com/c/Shopify-APIs-SDKs/GraphQL-query-for-fulfilled-orders-amp-other-filte...

https://community.shopify.com/c/Shopify-APIs-SDKs/Filtering-GraphQL-Orders-results/m-p/466007

Valid values for fulfillment_status is not as stated in the docs but values like "shipped" or "unshipped" or "partial" work. Unfortunately the pagination problem still exists.

0 Likes
GrahamS
Shopify Staff
Shopify Staff
47 8 2

Hello @TomSmith ,

After a second look, I can confirm what you are saying. I'll send in a request to have the documentation appended regarding those fulfillment values.

That said, even when using your exact syntax and parameters, I wasn't able to to replicate your result against my test store, regardless of what value I pass for my limit - each payload returned the expected result. With that in mind, I'd like to take a look at your specific shop data and header request ID for your most recent attempt. Can I ask for you to DM to me your shop name, as well as the x-request-id of a recent failed payload?

Graham S | API Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
GrahamS
Shopify Staff
Shopify Staff
47 8 2

This is an accepted solution.

Hey @TomSmith ,

Checking back in here. We were able to replicate the situation you're encountering and have an explanation for what you're seeing. Basically, your app is missing the scope permission for accessing order data that is older than 60 days old - the regular Orders scope only applies to data that is less than 60 days old.

What's happening is you are calling for all orders that are open and unshipped, and the first page of returned data is older than 60 days old and not scoped to your app, so it appears as an empty array with a next page = true. You might have to push through a few pages before you get to data that your app could actually display based on the existing configuration. This also explains why you eventually get some data back as you increase the order quantity per page in your variables.

There are two good options to get around this - you can request/grant the necessary scope to read all orders. From our docs:

21-41-m7mbw-q9m3b

 

Alternative, you can add another query filter to specify for orders that are less than 60 days old - "status:open -fulfillment_status:shipped created_at:>2021-05-03T00:00:00Z" as an example would return data in your existing call.

Thanks for being patient on this one! Hope this helps, and we're having the docs reviewed to see if we can have this clarified a bit.

Graham S | API Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog

0 Likes