# Pagination

> How lists are split into pages with page and limit, the pagination block in the response, how to walk through everything and how filters and pagination combine.

Large lists (members, statement, feed, products) come in pages. You ask for a page with two parameters and get back, along with the items, the `pagination` block.

## The parameters

| Parameter | What it is | Default | Maximum |
|---|---|---|---|
| `page` | The page, starting at 1 | 1 | — |
| `limit` | Items per page | 20 | 100 |

```bash
curl -s "https://api.memberfy.net/api/profiles/list?page=2&limit=50" \
  -H "Authorization: Bearer $TOKEN" \
  -H "X-CommunityId: $COMMUNITY_ID"
```

## The response

```json
{
  "success": true,
  "message": "…",
  "data": [ { "…": "…" } ],
  "pagination": { "page": 2, "limit": 50, "total": 137, "totalPages": 3 }
}
```

| Field | What it is |
|---|---|
| `page` | The page returned |
| `limit` | Items per page |
| `total` | How many items exist, with filters already applied |
| `totalPages` | How many pages there are |

## Walking through everything

```js
let page = 1;
const all = [];
while (true) {
  const { data, pagination } = await api.profiles.getList({ page, limit: 100 });
  all.push(...data);
  if (page >= pagination.totalPages) break;
  page += 1;
}
```

## Filters and pagination

Filters (`search`, `role`, `type`, `status`…) are applied **before** paginating: `total` and `totalPages` only count what matches the filter.

## Tips

- Use the largest `limit` that makes sense (up to 100) to make fewer calls.
- Don't assume every list is paginated: when one isn't, the `pagination` block doesn't come back and `data` holds everything.
- When walking through a list that changes while you read it (the feed, for example), an item may show up on two pages; deduplicate by `id`.

## Related

- [Responses and errors](/api/respostas-e-erros)
- [JavaScript SDK](/api/sdk-js)
