Discussing APIs and development related to customers, discounts, and order management.
Hey everyone, not sure who to ask or where to find the solution - but I've noticed that when making API requests to `admin/orders` with pagination and limits, it's skipping over a record on every page...
For instance:
`admin/orders?page=1&limit=10` returns 1001 - 1010 : this is fine
`admin/orders?page=2&limit=10` returns 1012 - 1021 : missing 1011
`admin/orders?page=3&limit=10` returns 1023 - 1032 : missing 1022
`admin/orders?page=4&limit=10` returns 1034 - 1043 : missing 1033
Does anyone have any input on why this is happening?
:edited:
Also to clarify that in the query string we're using `status=any` and `financial_status=any` and `fulfillment_status=any` etc... it's just the pagination that's off.
Anyone from @shopify here to answer a question?
It not exactly sure why this is happening, but have you tried using since_id instead? It's a more performant way to execute these requests and is much more recommended when paginating.
`admin/orders.json?limit=10&since_id=0`
`admin/orders.json?limit=10&since_id=10`
`admin/orders.json?limit=10&since_id=20`
etc.
Alex | 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 the Shopify Help Center or the Shopify Blog
Hey thanks for responding Alex! No we haven't used the 'since_id' yet - and we can certainly give that a try - but the app is currently written to use pagination with a "page" and a "limit" parameter and we'll have to make some bigger changes to allow for this on historical syncing.
Can you please see if you get the same results on a dev store of yours using pagination the way ( most people would use it )?
... tried to respond and it duplicated it ... sorry.
I interestingly cannot replicate this on my test store using `page` and `limit` in tandem. Happy to make this against the shop you're seeing this on. Just give me an X-Request-Id and I can connect the dots from there if you aren't comfortable sharing teh shop address itself.
Alex | 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 the Shopify Help Center or the Shopify Blog
Hey Alex,
Using this query string: /admin/orders.json?page=2&limit=10&status=any&financial_status=any&fulfillment_status=any&direction=asc
Call 1 ID: cb977b65-a38b-4b9e-9138-cd09bc785892
Call 2 ID: 969f44d1-1cd3-4f8a-aa18-eaf9eaeecd6f
Thanks!
Alex, I was actually able to implement the "since_id" and that works fine... but I can't help but wonder how many people the typical pagination is effecting. I would still like to know the answer when you get a chance - but just wanted to report back here that making the change in the application to use that param works great.
Is there ever a time where any resource type won't have a valid ID to use for paginating? Like a guest customer for example?
Hey Ryan,
I haven't investigated yet on my end but it's on my todo. I just wanted to answer your most recent question:
The ID field is guaranteed to be present and valid on all resources. There's no chance you will not be able to use an ID to paginate. If the resource exists, it will have a valid ID.
I'll post back here when I've had a chance to look into the issue you're seeing with page and limit.
Alex | 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 the Shopify Help Center or the Shopify Blog
Hey Ryan,
Update for you. I was able to consistently replicate this issue when using the `direction` parameter. This does not appear to be documented, and by extension it isn't a supported approach. It's definitely a bug, but it doesn't look like it's one we're going to fix if it's not supported. Nice work porting to since_id.
Cheers.
Alex | 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 the Shopify Help Center or the Shopify Blog
Ah - thanks Alex. That's interesting to hear that you don't support typical pagination like that. I see you have a "page" and you have a "limit"... so whats the point of the "page" parameter in an API call?
https://help.shopify.com/en/api/reference/orders/order#index shows you support the "page", "limit" params etc.
I get why it's more performant to use the "since_id" but it just threw us for a loop when orders were missing from the pagination calls we had previously wired up. I just want to make sure we fully understand the best practices using the API.
Again - thanks for the responses - much appreciated
To clarify: We do support using page and limit, but we recommend using since_id and limit. What we don't support is paginating in reverse via `direction`. When not using `direction`, I could not replicate the issue.
Alex | 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 the Shopify Help Center or the Shopify Blog
Ah - I'm sorry I didn't catch that previously. OK that's good enough for us. The since_id is fine now that we know, but I could have sworn you had that param supported "direction" at one point.
Thanks again - consider this one CLOSED 🙂