Pagination
API resources support pagination for large collections. Methods include token pagination (for the entity endpoint) and offset pagination (for all others). To navigate the API efficiently, you’ll need an understanding of these methods.
Token Pagination
We utilize token pagination within the entity endpoint (relationships, possibly_same_as, and referenced_by), where payload size and dynamic item count make this the most effective method.
How it works
- Each request returns a token (e.g.,
next
orprev
) in the response. - You can use this token in the next request to fetch the subsequent set of data.
- If there is no token in the request, our platform defaults to the first page of results.
limit
controls the number of items per page, with a maximum and default value specific to each endpoint. The typical default value is 100.
Arguments
Example
next=qr7bvn2
: Fetch the next page of relationships with a specific token.limit=10
: Restrict the results to 10 items per page.
Offset Pagination
Offset pagination is straightforward and used when the total item count is known. It is utilized in most endpoints.
How it works
- Users fetch data based on
offset
(start point) andlimit
(number of items to return). offset
defines the starting point by skipping a set number of items.limit
sets the maximum items to be returned in a response.- Metadata in the response indicates the availability of more data.
Arguments
Example
offset=20
: Begin results from the 21st object.limit=50
: Restrict the results to 50 items per page.
Paginating Search
Search queries can return many results. Use offset pagination to manage them efficiently.
Example
offset=100
: Starts the results from the 101st object.limit=50
: Limits the number of results to 50 per page.
The API response will include information about the availability of additional data:
- The
count
field indicates the number of results (10,000 is the max). There may be more results in this response example. - The
next
field indicates whether more results are available beyond the current page. - Subsequent requests can adjust the
offset
to access further results.
Paginating Entities
When working with entities in the Sayari API, you’ll find that each entity can have multiple attributes and relationships, which often leads to extensive datasets. Use token pagination to manage these results efficiently. Pagination “next” or “prev” tokens are passed as query parameters.
Example combinations
attributes.[field].['next' | 'prev']=[string]
|?attributes.address.next=qr7bvn2
relationships.['next' | 'prev']=[string]
|?relationships.next=qr7bvn2
possibly_same_as.['next' | 'prev']=[string]
|?possibly_same_as.next=qr7bvn2
referenced_by.['next' | 'prev']=[string]
|?referenced_by.next=qr7bvn2
Examples
attributes.name.limit=10
: Limits the number of name attributes to 10 per page.relationships.next=qr7bvn2
: Uses a token to fetch the next page of relationships.relationships.limit=200
: Sets a limit of 200 for the number of relationships per page (which is the maximum for relationships).
The API response will include information about the availability of additional data:
- The
count
field indicates the number of results per attribute. - The
next
&prev
fields contain tokens that can used in the subsequent request to fetch the next or previous set of data. - The
limit
field indicates the limit per attribute.
Paginating Records
For records that reference numerous entities, pagination is key to accessing this data in a manageable way. Records utilize offset pagination.
Example
offset=100
: Starts the results from the 101st object.limit=50
: Limits the number of results to 50 per page.
The API response will include information about the availability of additional data:
- The
count
field indicates the number of results. - The
next
&prev
fields contain tokens that can used in the subsequent request to fetch the next or previous set of data. In the instance below, “next” isfalse
, indicating there are no more results. - The
limit
field indicates the limit returned.
Paginating Traversals
The traversal endpoints’ response paths are paginated via offsets. Because the total number of potential matching paths is very expensive to compute, the response does not include size values. Instead, use the next
boolean field to determine if there are more pages of results to return.
Example
offset=20
: Starts the results from the 21st object.
The API response will include information about the availability of additional data:
- The
next
&prev
fields contain tokens that can used in the subsequent request to fetch the next or previous set of data. In the instance below, “next” istrue
, indicating there are more results. - The
limit
field indicates the limit returned.