# Pagination

Glomo's API endpoints that return collections of data (such as lists of payments, customers, or transactions) support pagination. This allows you to control the number of records returned in a single API response and navigate through large datasets efficiently.

## Overview

- **Default Pagination**: By default, API endpoints returns 20 records per request.
- **Pagination Parameters**: Use query parameters to specify the page number and the number of records per page.
- **Response Metadata**: Each paginated response includes metadata about the pagination state.


## Parameters

When making a request to an endpoint that supports pagination, you can include the following query parameters:

- **page**: `integer` page number to retrieve. Starts from 1.
  - Default: `1`
- **per_page**: `integer` number of records to return per page.
  - Default: `20`
  - Maximum: `100`
- **before**: `timestamp` UTC Timestamp, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) format, before which the entities are created.
- **after**: `timestamp` UTC Timestamp, in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) format, after which the entities are created.


Use `before` or `after` timestamps to ensure consistent results and avoid **Page drift**. A page drift is a case which happens in case new records were added to the result set while you were traversing a series of pages. The new records will end up pushing some older results into your new pages hence resulting in duplicated values in 2 subsequent pages.
Using the timestamps will restrict the search window and prevent new records from seeping into the current result set.

## Example Request and Response

### Retrieving a List of Payments with Pagination

## Request


```http
GET /v1/payments?page=2&per_page=20
Authorization: Bearer YOUR_SECRET_KEY
Content-Type: application/json
```

## Response


```http
{
  "data": [
    {
      "id": "payt_E602dMzgjpDC",
      "payin_id": "payin_E602dMzgjpDC",
      "status": "success",
      "currency": "USD",
      "amount": 1,
      "credit_account_number": "string",
      "debit_account_number": "string",
      "purpose_code": "S0001",
      "transaction_reference_number": "payin_E602dMzgjpDC",
      "sender_name": "John Doe",
      "metadata": {},
      "error_message": "string",
      "payment_date": "2024-12-06T11:38:37.130Z",
      "created_at": "2024-12-06T11:38:37.130Z",
      "updated_at": "2024-12-06T11:38:37.130Z",
      "customer_id": "cust_E602sMzgjpDC",
      "country": "Ind",
      "ordered_amount": 1000,
      "ordered_currency": "USD",
      "fx_fee": {
        "amount": 1000,
        "currency": "USD"
      },
      "txn_fee": {
        "amount": 1000,
        "currency": "USD"
      },
      "documents": [
        {
          "id": "doc_nYUqLpuYQ0M8",
          "type": "invoice",
          "status": "pending",
          "rfi_doc_id": "rfidoc_nYUqLpuYQ0M8"
        }
      ]
    }
  ],
  "page_meta": {
    "current": 2,
    "previous": 1,
    "next": 3,
    "per_page": 20,
    "pages": 10,
    "count": 200
  }
}
```