LendWorksLendWorksDocs

Pagination

Navigate through large result sets with page-based pagination.

Overview

All list endpoints return paginated results. The default page size is 20 items, with a maximum of 100.

Query Parameters

ParameterTypeDefaultMaxDescription
pageinteger1Page number (1-indexed)
limitinteger20100Items per page

Response Metadata

Collection responses include pagination metadata in the meta object:

{
  "data": [
    { "id": "...", "type": "lead", "attributes": { ... } },
    { "id": "...", "type": "lead", "attributes": { ... } }
  ],
  "meta": {
    "total": 142,
    "page": 1,
    "limit": 20,
    "hasMore": true,
    "requestId": "550e8400-e29b-41d4-a716-446655440000"
  }
}
FieldTypeDescription
totalintegerTotal number of matching records
pageintegerCurrent page number
limitintegerItems per page
hasMorebooleanWhether more pages exist
requestIdstringRequest correlation ID

Examples

Basic Pagination

# First page (default 20 items)
curl -H "Authorization: Bearer lw_live_xxxx" \
     https://api.lend.works/v1/leads

# Second page with 50 items per page
curl -H "Authorization: Bearer lw_live_xxxx" \
     "https://api.lend.works/v1/leads?page=2&limit=50"

Iterating All Pages

import { LendWorksClient } from '@lendworks/sdk-node'

const client = new LendWorksClient({ apiKey: 'lw_live_xxxx' })

let page = 1
let hasMore = true

while (hasMore) {
  const result = await client.leads.list({ page, limit: 100 })

  for (const lead of result.data) {
    console.log(lead.attributes.businessName)
  }

  hasMore = result.meta.hasMore
  page++
}

With fetch

async function fetchAllLeads() {
  const leads = []
  let page = 1

  while (true) {
    const res = await fetch(
      `https://api.lend.works/v1/leads?page=${page}&limit=100`,
      { headers: { Authorization: 'Bearer lw_live_xxxx' } }
    )
    const { data, meta } = await res.json()
    leads.push(...data)

    if (!meta.hasMore) break
    page++
  }

  return leads
}

Sorting

List endpoints return results sorted by createdAt in descending order (newest first) by default. Endpoints that support search may return results sorted by relevance when a search term is provided.

Best Practices

  • Use the smallest limit that meets your needs to reduce response time
  • Check hasMore rather than comparing page * limit < total to handle concurrent changes
  • For large exports, iterate with limit=100 and process in batches
  • Cache page results client-side when appropriate to reduce API calls