API Client
|
Model::getList() and Model::getRelated() methods return an instance of ListResult class. When calling these methods, API returns a limited number of record, as specified by $limit
argument. There may be more data available, and if you want to retrieve it, you need to send additional requests, adjusting $offset
argument accordingly.
To get total number of results matching your request, call ListResult::totalResults() :
Although only 5 results were returned as we requested, we see that there is additional data available. If you want to iterate over all results, and not a limited subset, you will need to send multiple requests. For example if there are 500 total results, and you fetch the results in chunks of 100, you will need 5 requests:
Request # | $offset | $limit |
---|---|---|
1 | 0 | 100 |
2 | 100 | 100 |
3 | 200 | 100 |
4 | 300 | 100 |
5 | 400 | 100 |
ListResult provides a generator()
method that returns a PHP generator for use in foreach
loop. When iterating, it will send additional requests as needed to iterate over all records: