Paginated ResultsΒΆ
All REST endpoints that return a long list of results use a Pagination object to limit the amount of results returned in a single query.
Every Pagination object has the following properties:
Property | Type | Description |
---|---|---|
Required Properties | ||
next | string | URL of the next page of results, or null if this is the last page. |
previous | string | URL of the previous page of results, or null if this is the first page. |
results | list | The list of results. |
When a query has more results than the requested amount (50 by default), the
next
property of the returned object contains a URL which will return the next
list of results, starting with the result immediately following the last one in
the current list. If there are no additional results, the next
property will be null
.
The following example demonstrates how to use the previous
and next
properties
to gather the full list of Conversations from the List conversations endpoint.
import requests
# List where we will store the Conversation objects
results = []
next_url = 'https://api.gridspace.com/v0/conversations'
while next_url:
response = requests.get(next_url, auth=(ACCOUNT_ID, AUTH_TOKEN))
# Raise an exception if we didn't get a success status code
response.raise_for_status()
page = response.json()
# Concatenate the lists
results += page['results']
next_url = page['next']