Pagination

Offset-based pagination for navigating large result sets in the ADP API

Pagination

The ADP API uses offset-based pagination to navigate large result sets efficiently.

Pagination Parameters

ParameterTypeDefaultDescription
limitInt25Maximum items to return per page
offsetInt0Number of items to skip

Pagination Formula

Page N: offset = (N - 1) × limit

PageLimitOffsetItems Returned
11001-10
2101011-20
3102021-30

Connection Structure

🚧

ADP API uses a custom Connection structure WITHOUT the standard node wrapper.

Standard GraphQL Connection (NOT used by ADP API)

lineitems {
  edges {
      lineitem_id
      lineitem_name
    }
  pageInfo {
    hasNextPage
  }
}

ADP API Connection (actual structure)

lineitems {
  edges {
    lineitem_id
    lineitem_name
  }
  total_count
}

Key Differences:

  • ✅ Items in edges array (same as standard)
  • ❌ NO node wrapper (different from standard)
  • total_count field (instead of pageInfo)
  • snake_case naming (not camelCase)

Examples

First Page (Items 1-10)

query GetFirstPage {
  dream_adserver {
    lineitems(limit: 10, offset: 0) {
      edges {
        lineitem_id
        lineitem_name
      }
      total_count
    }
  }
}

Second Page (Items 11-20)

query GetSecondPage {
  dream_adserver {
    lineitems(limit: 10, offset: 10) {
      edges {
        lineitem_id
        lineitem_name
      }
      total_count
    }
  }
}

Calculate Total Pages

const limit = 10;
const totalCount = 142; // From response.total_count
const totalPages = Math.ceil(totalCount / limit); // = 15 pages

Common Mistakes

❗️

❌ WRONG: Using node wrapper

lineitems {
  edges {
      lineitem_id
    }
}

✅ CORRECT: Direct access in edges

lineitems {
  edges {
    lineitem_id
  }
}
❗️

❌ WRONG: camelCase totalCount

lineitems {
  totalCount
}

✅ CORRECT: snake_case total_count

lineitems {
  total_count
}

Best Practices

  • Use total_count to calculate total pages before pagination
  • Combine with sort for consistent ordering across pages
  • Keep limit reasonable (25-100 items) for performance
  • Cache results when possible to reduce API calls

Complete Example

query GetPaginatedLineitems($filter: JSON, $sort: JSON, $limit: Int, $offset: Int) {
  dream_adserver {
    lineitems(
      filter: $filter
      sort: $sort
      limit: $limit
      offset: $offset
    ) {
      edges {
        lineitem_id
        lineitem_name
        lineitem_type
      }
      total_count
    }
  }
}

Variables:

{
  "filter": {"lineitem_is_archived": {"=": false}},
  "sort": {"lineitem_id": "desc"},
  "limit": 10,
  "offset": 0
}

Next Steps