Invalid cursor error (#613) when paginating large datasets with Graph API cursor pagination
0 reputation · 13 Oct 2021, 20:39 UTC
Goal
Bound a Graph API query and paginate through a large result set using cursor-based pagination without encountering the (#613) Invalid cursor error.
Constraints and uncertainty
Cursor tokens expire or become malformed after a short window, and the API does not disclose the total result count, making it difficult to estimate progress. Ordering stability is not guaranteed when the underlying index changes, which can introduce duplicates or gaps across pages. Aggressive limit values risk rate limiting, while very small limits increase request overhead and the chance of cursor expiration.
Questions
- What is the documented lifetime of an
aftercursor token, and can it be refreshed without restarting the query? - How should a client detect and recover from an invalid cursor without losing position in the dataset?
- Is there a recommended pattern for bounding the initial query (e.g., time range, ID range) to minimize cursor instability on very large collections?