169
Views
3
Comments
Solved
Pagination - Rest API
Application Type
Mobile
Service Studio Version
11.53.16 (Build 61323)

Good afternoon All,

I hope you are well! 

I have recently launched my app business and have a few customers in the pipeline, however I have come across two key issues with this current app that I can't seem to overcome and time is very pressing now. I will only talk about my first obstacle here.

The current issue/ obstacle I can't figure out is how I can check all the Products currently being pulled through in the rest API call, or should I say, all the products that are on the WooCommerce Store for the customer.

The API is linking to the customers WooCommerce store as intended and WooCommerce does also offer pagination which is handy. I just don't know how to make my Category page (or any page that needs to filter results) run through each product to filter them based on their Parent (or Category) Id. Currently it just pulls through the one page of results. It does however filter the one page as it should if there is a product with a matching Category Id. The Category Id is passed in from the previous screen. 

I currently have the REST API setup to list 100 products per page using "?per_page=100" and I can see from the call that there are 13 pages over all (if 100 products are listed per page). There's roughly 1225 products or something in my customers store. As I say, I don't know what I need to do to make sure the sever action runs through all 13 pages and then only display the products that are relevant.

As of now, my screen just calls the base API and then using a ListFilter, it filters whatever 100 products are pulled through and displays those relevant based on the passed Category Id.

Once I figure this out I'm sure I can repeat this solution in other screens and apps, I just need guidance on how to effectively implement it/ best practice.

Any guidance is greatly appreciated! 

Thanks, Josh

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Josh,

As you have already noticed, your solution isn't a very handy one :). Typically, REST APIs that let you get paginated lists of stuff also let you filter on stuff. So my first step would be to check the WooCommerce REST API to see if it offers filtering. And... whaddayaknow:

There's a lot of other filters as well. So, do not use ListFilter to filter paginated results after the fact, but use the REST API's capabilities to filter.

UserImage.jpg
Joshua McQuillan

Hi Kilian,

That's very annoying that I just completly looked over that field... I know I had seen it before as well but I was clearly too tunnel vision to consider my options!!

This worked a charm and I actually used it as a solution the very same evening - so thanks again Kilian!

Josh

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

You're most welcome, glad I could be of help :).

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.