Azure DevOps REST API and Graph API: Pagination and Offset Support
0 reputation · 18 Jan 2021, 03:59 UTC
0 reputation · 18 Jan 2021, 03:59 UTC
When retrieving large datasets from Azure DevOps, the REST API typically employs server-side pagination. For many endpoints, this is managed via the x-ms-continuationtoken header, which allows clients to request subsequent pages by passing a continuationToken parameter.
While standard OData-style parameters like $top are supported to limit result sets, the Azure DevOps Graph API exhibits specific behavior regarding offsets. Documentation indicates that $skip is not honored for most collection-based endpoints, often resulting in a 400 Bad Request error when attempted.
This creates a discrepancy for integrations that require random access to specific pages of a dataset rather than sequential traversal via continuation tokens. There is currently no documented mechanism within the Graph API to jump to a specific record offset without iterating through all preceding pages.
$skip for non-sequential data access?34775 reputation · 18 Jan 2021, 12:53 UTC
The Azure DevOps Graph API does not provide a documented alternative to $skip for non-sequential data access. Continuation-token traversal is the only supported pagination method for Graph API collection endpoints. There is no documented offset-based path that lets a client jump to a specific record without iterating through preceding pages.
continuationToken query parameter.x-ms-continuationtoken response header.$top to limit page size on many collection endpoints.$skip is generally unsupported on Graph API collection endpoints and typically returns 400 Bad Request.Graph endpoints traverse relationships rather than scan flat tables, so the service may not maintain a stable ordinal position for records across requests. Implementing $skip would require materializing and numbering the full result set before applying the offset, which is expensive for graph traversals. The service therefore exposes continuation tokens as an opaque cursor instead of a skip count.
$top=10.x-ms-continuationtoken.continuationToken in the next request to retrieve the following page.$skip=10 in production calls; expect 400 Bad Request on most Graph API collection endpoints.GET https://app.vssps.visualstudio.com/_apis/graph/...?api-version=7.0&$top=10
# Response header: x-ms-continuationtoken: OPAQUE_TOKEN
GET https://app.vssps.visualstudio.com/_apis/graph/...?api-version=7.0&$top=10&continuationToken=OPAQUE_TOKEN
api-version parameter in your integration.400 Bad Request behavior for $skip against your target endpoint before relying on it.Do you need random access to a specific record by position, or is sequential traversal acceptable? If you require true random access, the recommendation changes to fetching and caching pages client-side or filtering by a stable identifier rather than using an offset.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.