Skip to content
Dashboard

Pagination

Navigate through large result sets efficiently with cursor-based pagination.

Query Parameters

All list endpoints accept the following pagination parameters:

ParameterTypeDefaultDescription
pageinteger1Page number (1-indexed)
limitinteger20Results per page (1-100)
sortstringcreated_atField to sort by (varies by endpoint)
orderstringdescSort direction: asc or desc

Response Format

Every paginated response includes a pagination object alongside the data array, providing all the information you need to navigate through result pages.

200Paginated response
{
  "success": true,
  "data": [
    "..."
  ],
  "pagination": {
    "total": 142,
    "page": 2,
    "limit": 20,
    "total_pages": 8,
    "has_more": true
  }
}

Pagination Fields

FieldTypeDescription
totalintegerTotal number of matching records
pageintegerCurrent page number
limitintegerResults per page
total_pagesintegerTotal number of pages
has_morebooleanWhether more pages exist after the current one

Iterating All Pages

To fetch all records, loop through pages until has_more is false:

async function fetchAllArticles(apiKey) {
  const articles = [];
  let page = 1;
  let hasMore = true;

  while (hasMore) {
    const res = await fetch(
      `https://brainpercent.app/api/v1/articles?page=${page}&limit=100`,
      { headers: { 'Authorization': `Bearer ${apiKey}` } }
    );
    const { data, pagination } = await res.json();
    articles.push(...data);
    hasMore = pagination.has_more;
    page++;
  }

  return articles; // All articles
}

Sorting

Each endpoint supports a set of sortable fields. Use the sort and order parameters to control result ordering.

EndpointSort Fields
/api/v1/articlescreated_at, updated_at, title
/api/v1/social/contentcreated_at, updated_at, platform
/api/v1/projectscreated_at, updated_at, name
// Get newest articles first (default)
const res = await fetch(
  'https://brainpercent.app/api/v1/articles?sort=created_at&order=desc',
  { headers: { 'Authorization': 'Bearer bp_your_key' } }
);

// Get articles alphabetically
const res2 = await fetch(
  'https://brainpercent.app/api/v1/articles?sort=title&order=asc',
  { headers: { 'Authorization': 'Bearer bp_your_key' } }
);

Combining Filters with Pagination

Filter parameters can be combined with pagination and sorting to narrow down results efficiently:

// Get published articles from a specific project, page 2
const res = await fetch(
  'https://brainpercent.app/api/v1/articles?status=published&project_id=d290f1ee-6c54-4b01-90e6-d701748f0851&page=2&limit=25&sort=updated_at&order=desc',
  { headers: { 'Authorization': 'Bearer bp_your_key' } }
);

Best Practices

  • Use limit=100 (maximum) when fetching all records to minimize requests
  • Always check has_more rather than comparing page to total_pages
  • Add a small delay between page requests to respect rate limits
  • Cache total counts if you only need them for display purposes
  • Use filters to reduce result sets before paginating