Home App Docs Blog Github

How can I know if there are more records to fetch from the Content / Query API?

I can make a request on the content API, which will return a number of records. For example, I have a Recipe model, and I can run a request on /api/v1/query/recipes and include search terms on attributes of that model.

This returns records that match the search terms given:

Is there a way for me to know if there are more records to page through, that aren’t included in the first response?

I know I can put the limit to be up to 100, but I’m wondering about this for features on my site where I’d like to paginate results, for example starting with the first 10, and knowing whether there are more past that first 10 to continue to request. (Or, for example, if there are more than 100 recipes that match a search).

@jballo currently there is not a built in pagination field within the API resposne. However there a few ways you could get around this. I would say the most straight forward would be to set the limit to be 1 over what you are looking for, and if the length of the response is greater then you know there will be more results.

So for example if you want 10 recipes per page, do your API call limit to 11, displaying only 10 results on the page. If the response has 11 results you, you know there are more results left, if the response is less than 10 you will know that you have reached the end.

Or you could set limit to 10, and if the response has 10 items, do another request and see if there are any items in the response.

Hopefully that helps!