> ## Documentation Index
> Fetch the complete documentation index at: https://guide.withvayu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

> How to work with paginated list responses

All list endpoints return a consistent paginated response shape.

## Response format

```json theme={null}
{
  "customers": [...],
  "total": 2783,
  "hasMore": true,
  "nextCursor": "eyJpZCI6IjEyMyJ9"
}
```

| Field        | Type    | Description                                                           |
| ------------ | ------- | --------------------------------------------------------------------- |
| `[resource]` | array   | The list of items (e.g. `customers`, `events`, `invoices`)            |
| `total`      | number  | Total count of items in the collection — unaffected by `limit`        |
| `hasMore`    | boolean | `true` if more results exist beyond this page                         |
| `nextCursor` | string  | Cursor to pass in the next request — absent when `hasMore` is `false` |

## Request parameters

| Parameter | Default | Max   | Description                                              |
| --------- | ------- | ----- | -------------------------------------------------------- |
| `limit`   | 10      | 1,000 | Number of items to return                                |
| `cursor`  | —       | —     | Cursor from the previous response to fetch the next page |

## Iterating all pages

<CodeGroup>
  ```typescript TypeScript theme={null}
  async function fetchAll<T>(
    fetchPage: (cursor?: string) => Promise<{ data: T[]; hasMore: boolean; nextCursor?: string }>
  ): Promise<T[]> {
    const results: T[] = [];
    let cursor: string | undefined;

    do {
      const page = await fetchPage(cursor);
      results.push(...page.data);
      cursor = page.nextCursor;
    } while (page.hasMore);

    return results;
  }
  ```

  ```python Python theme={null}
  def fetch_all(fetch_page):
      results = []
      cursor = None

      while True:
          page = fetch_page(cursor=cursor)
          results.extend(page.data)
          if not page.has_more:
              break
          cursor = page.next_cursor

      return results
  ```

  ```go Go theme={null}
  import VayuSDK "github.com/weft-finance/vayu-go"

  vayu := VayuSDK.NewVayu(os.Getenv("VAYU_API_TOKEN"))

  var cursor *string
  for {
      resp, err := vayu.Customers.ListCustomers(nil, cursor)
      if err != nil {
          panic(err)
      }
      for _, c := range resp.Customers {
          fmt.Println(c.Id)
      }
      if !resp.HasMore {
          break
      }
      cursor = &resp.NextCursor
  }
  ```
</CodeGroup>
