Pagination & Sorting
How to easily page through large datasets.
Most of Raisely's index endpoints support pagination and sorting.
Specifically, performing a GET request on /campaigns, /comments, /donations, /profiles, /posts, /subscriptions, or /users supports standard pagination and sorting.
When you request a collection that supports pagination, it will include additional information to help with pagination.
You can use the following query parameters to control pagination and sorting
Query Parameter | Default Value | Description |
---|---|---|
limit | 100 | The maximum number of records to return in this request. |
offset | 0 | The number of records to skip ahead by. |
order | desc | The direction to order the sort column. Can be asc or desc. |
sort | createdAt | Selects a column to order the results by. |
Every paginated request includes a pagination object in the response, the pagintation object contains the following information about pagination.
Pagintation Attribute | Example | Description |
---|---|---|
limit | 10 | The maximum number of records returned in the request. The same as the query parameter, or the default if it wasn't specified. |
nextUrl | https://api.raisely.dev/v3/campaigns/d1412500-3ef0-11e7-ba8f-00254ba2a4bb/profiles?sort=goal&order=desc&limit=5&offset=15 | The url of the next page of results. If you are on the last page of results, this will be false. |
offset | 15 | The offset that was requested, or 0 if it was unspecified |
pages | 5 | The total number of pages |
prevUrl | https://api.raisely.dev/v3/campaigns/d1412500-3ef0-11e7-ba8f-00254ba2a4bb/profiles?sort=goal&order=desc&limit=5&offset=5 | The url of the previous page of results. If you are on the first page of results this will be false. |
total | 23 | The total number of records available. |
Example
// Fetch profiles ordered by fundraising goal from highest to lowest
// 5 profiles per page, show the 3rd page.
let url = `https://api.raisely.com/v3/campaigns/${campaignUuid}/profiles`;
let query = '?sort=goal&order=desc&limit=5&offset=10';
let profiles = yield request({
method: ‘GET’,
url: url + query,
});
console.log(profiles);
// Will show something like ...
{
data: [<5 profile objects>]
pagination: {
limit: 5, // The maximum number of records you requested
nextUrl: "https://api.raisely.com/...", // Url for the next page
offset: 10, // The offset you requested
pages: 5, // The total number of pages
prevUrl: "https://api.raisely.com/...", // Url for the previous page
total: 22 // The total number of records available
}
}
Updated almost 4 years ago