Pointer Based Pagination For Draft Orders

Highlighted
Shopify Partner
26 0 1

Hi there!

 

In attempting to upgrade to pointer based pagination when using the draft_order endpoint, there are a few conceptual issues that make it difficult to use effectively.

 

The issue is in regard to sorting. There is no way to sort the API results so that the most recently created or updated draft orders are displayed first. With page based API calls, we could simply reverse the order of the pages shown, and get the desired result, or skip to the last page. With pointer based pagination, the only option to find the most recent page of draft orders is to make api calls until each page shown, then return the last page.

 

Additional search and filtering options for this API feature would be greatly beneficial!

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 119

Hey @PixApps ,

 

If you are using the GraphQL Admin API, what you are trying to accomplish would be relatively easy to do. All you need to do is keep track of the Cursor ID that corresponds to your most recent Draft Order. Once you know this, you can pull the most recently created/updated draft orders through cursor-based pagination like so:

 

query {
	draftOrders(last: 10, before:"eyJsYXN0X2lkIjoyMzMxNjY1MDM5NTgsImxhc3RfdmFsdWUiOiIyMzMxNjY1MDM5NTgifQ==") {
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
    edges {
      cursor
      node {
        id
        createdAt
      }
    }
  }
}


To do this in REST Admin API, like you said, you would need to look at the "link" response header in the Shopify API response and follow the 'rel=next' URLs until you got to the last page. Then once you reached the last page, you can look at this "link" response header again but this time follow the 'rel=previous' URLs to iterate backwards 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Shopify Partner
26 0 1

Brilliant @hassain  - that's exactly what I was hoping for! I'll test it out, but that looks like it will work fantastically.

 

Thanks so much for the reply :)

0 Likes