Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Paginated results

Solved

Paginated results

manou_mhd
Tourist
4 0 1

I'm currently using the Shopify API to retrieve all the customers, products and orders. The problem is while testing the API in Postman, The API returns the "link" in the header containing the next page token, but from the thrid page I receive the same token. And I'm currently sending the request parameters only one time (in the first call).
I've tried using both 2022-01 and 2021-10 API version. Could you help please ? Thanks!

Accepted Solution (1)
awwdam
Shopify Staff
249 42 38

This is an accepted solution.

Hey @manou_mhd,

After a few requests to my test environment and emulating similar filters to those you used, I was able to paginate through several pages with everything working as expected per our documentation. 

You mentioned that you aren't including a limit parameter in the first request, which might be good preliminary troubleshooting. In the case that a larger volume of data is expected, starting with a count on the resource (orders) should give an idea of how many pages of orders need to be paginated through.

Shopify REST Pagination uses the link header returned, appending page_info=[VALUE]  and limit={<250} parameters. This allows navigation through the resource until there is no longer data to return, at which point a link to the previous page will be returned with the final page.

EG. first request /admin/api/2021-10/orders.json?{filters}&status=any?limit={<250}, second request /admin/api/2021-10/orders.json?page_info={VALUE}&limit={<250}, etc.

Locating request logs for the example IDs shared, I noticed that none of the endpoint URLs include a cursor? Based on this and info above, taking a look back through the documentation should help clarify formatting and process.

If you still feel something isn't working, share any additional example URLs and we can have a look again to provide next steps. 

Cheers! 

awwdam | 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

View solution in original post

Replies 8 (8)

awwdam
Shopify Staff
249 42 38

Hey @manou_mhd,

Would you be able to provide me with an example of one of the requests that you are making (request body), as well as an x-request-id header value that was returned with the response. I also wanted to ask if you are using our REST pagination docs, if not I would suggest taking a look through to confirm functionality.

I would be happy to take a closer look and pass back any insights from there - Cheers!

awwdam | 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

manou_mhd
Tourist
4 0 1

Hello @awwdam ,
Thank you for answering me! 

I've checked the documentation of REST pagination, and I'm only sending the parameter updated_at_min="2022-01-01" in the first call without sending page_info, then I'm only sending page_info and limit in the request header.

Here's the X-Request-ID sent in my first request : c6008be9-5f06-4e59-8a63-dc0de735b8e8
Here's the one which returns the same Link in the response header : 649651d4-73d8-443d-a7fd-cd0bb083e143


awwdam
Shopify Staff
249 42 38

This is an accepted solution.

Hey @manou_mhd,

After a few requests to my test environment and emulating similar filters to those you used, I was able to paginate through several pages with everything working as expected per our documentation. 

You mentioned that you aren't including a limit parameter in the first request, which might be good preliminary troubleshooting. In the case that a larger volume of data is expected, starting with a count on the resource (orders) should give an idea of how many pages of orders need to be paginated through.

Shopify REST Pagination uses the link header returned, appending page_info=[VALUE]  and limit={<250} parameters. This allows navigation through the resource until there is no longer data to return, at which point a link to the previous page will be returned with the final page.

EG. first request /admin/api/2021-10/orders.json?{filters}&status=any?limit={<250}, second request /admin/api/2021-10/orders.json?page_info={VALUE}&limit={<250}, etc.

Locating request logs for the example IDs shared, I noticed that none of the endpoint URLs include a cursor? Based on this and info above, taking a look back through the documentation should help clarify formatting and process.

If you still feel something isn't working, share any additional example URLs and we can have a look again to provide next steps. 

Cheers! 

awwdam | 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

manou_mhd
Tourist
4 0 1

Hello again @awwdam ,

Thank you very much problem solved, I was sending the page_info in the request header instead of the body request. It's working now! 

Thank you !

yessiuk
Visitor
1 0 0

Hey, 

 

I'm stuck in a similar situation here @manou_mhd , do you mind sharing you code within Qlik Sense data load you used to retieve all orders within the loop?

Thanks
Simon

prateeks885
Shopify Partner
3 0 1

Hi Awwdam, 

 

I am also facing the same issue in postman. Using the count CURL - I have got the count for my customers and orders. Now I want to fetch the customers using pagination so how do I find the value forpage_info.

 

Here's approach which I am following;

 

Step 1 - Get count - https://store.myshopify.com/admin/api/2024-04/orders/count.json?status=any

Step 2 -  Get 1st 200 orders - https://store.myshopify.com/admin/api/2023-10/orders.json?limit=200

Step 3 - /admin/api/2021-10/orders.json?page_info={VALUE}&limit={<250} - now how I find / get the value for page_info

 

Kindly do let me know how can I run the same in Postman.

ShopifyDevSup
Shopify Staff
1453 238 522

Hi @prateeks885,

 

When making paginated calls to the REST API, the response header received from your query in step 2 will return a link with the page_info to use in your next call to paginate the results.

Here's an example from the Make paginated requests to the REST Admin API guide in our Shopify.dev documentation:

API Call:

GET https://{shop}.myshopify.com/admin/api/{api_version}/customers.json?limit=3

Response Header:

#...
link: "<https://{shop}.myshopify.com/admin/api/{api_version}/customers.json?page_info=hijgklmn&limit=3>; rel=next"
#...

Response Body:

{
 "customers": [
   {"id": 1},
   {"id": 2},
   {"id": 3}
 ]
}


With the example above, the initial API call is retrieving the first 3 customers on the store. The HTTP response header contains the link header, where you can use that link to make the next api call to retrieve the next "page" of results.

 

For more details on making REST paginated queries, you can refer to the Make paginated requests to the REST Admin API guide mentioned above.

 

I hope this helps, and I hope you have a great day 🙂

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

lucydana
Visitor
1 0 0

Hi! I'm having trouble parsing out the "page_info" from the "link" in the response header, so that I can include it in my subsequent API call as a URL parameter (using same base URL as before). Any suggestions?