Share via

Unable to retrieve test Plans After 20k records through Azure DevOps Rest API

Yash Tiwari 240 Reputation points
2025-09-15T06:45:53.7766667+00:00

Hi Team,

I'm unable to retrieve test Plans after 20k records through Azure DevOps Rest API and receiving this message:

{
    "$id": "1",
    "innerException": null,
    "message": "VS402337: The number of work items returned exceeds the size limit of 20000. Change the query to return fewer items.",
    "typeName": "Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemTrackingQueryResultSizeLimitExceededException, Microsoft.TeamFoundation.WorkItemTracking.Server",
    "typeKey": "WorkItemTrackingQueryResultSizeLimitExceededException",
    "errorCode": 0,
    "eventId": 3200
}
Azure DevOps

Answer accepted by question author

Anonymous
2025-09-19T06:16:22.5333333+00:00

@Yash Tiwari
If you're unable to receive a continuationToken, it means the API is failing at the very first step because the initial query is still trying to pull the full list and it's hitting the 20,000 work item limit before it can even start processing the request. This is a known behavior with certain Azure DevOps APIs when the total number of items in a collection is extremely large.

 

The reason it works now is that by manually reducing the number of test plans to under 20,000, you've removed the condition that triggers the size limit error. The API no longer has to handle an initial query that exceeds the limit, so it can return the results without an issue.

 

The "UI issue" you mentioned, where it says only 19,999 items will be fetched, is a direct reflection of this same size limit. It's Azure DevOps' way of telling you that it can't display all the data because of the query cap.

 

What to do moving forward

Since the API isn't providing a continuation token, your options are limited to filtering the data to reduce the result set of the initial query. You can't rely on pagination if the first call fails. Here are a few ways to filter your request to stay under the 20,000 limit, especially if you expect the number of test plans to grow again:

  •  Filter by Project: If you have multiple projects, query them one by one. The URL you're using already includes {{project}}, which is good. If your project has more than 20,000 test plans, you may need to apply further filtering.
  • Filter by Date Range: Retrieve test plans created or modified within a specific time frame. This is often the most effective way to manage large datasets.

 Example: You can use a query with a where clause to only get items from the last year or a specific month.

  • Filter by State: If you only need a subset of the data, query for test plans in a specific state, such as 'Active' or 'In Progress'.

Example of a filtered query:

You would have to switch to the Work Item Query Language (WIQL) API to apply these filters, as the Test Plan API doesn't support them directly.

 

POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=6.0

Content-Type: application/json

 

{

  "query": "Select [System.Id] From WorkItems Where [System.WorkItemType] = 'Test Plan' and [System.CreatedDate] >= '2025-01-01T00:00:00.00Z' Order By [System.Id]"

}

 

After you get the IDs from this WIQL query, you can then use them to retrieve the full Test Plan details. This two-step process is a common workaround for this type of issue.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Adharsh Santhanam 8,225 Reputation points Microsoft Employee Volunteer Moderator
    2025-09-15T07:18:18.6833333+00:00

    Hello Yash Tiwari, you're hitting a hard server-side limit in Azure DevOps: any work item query (WIQL or saved query) that would return >20,000 items fails with VS402337 and you can’t raise that cap in Azure DevOps Services. You must change the query or paginate via other APIs. See https://learn.microsoft.com/en-us/azure/devops/organizations/settings/work/object-limits?view=azure-devops#work-items-and-queries

    If you're using Test plans, use the Test Plan REST APIs which support paging with a continuation token in the response header - so you don't run into the 20k WIQL limit. See https://learn.microsoft.com/en-us/rest/api/azure/devops/testplan/test-plans/list?view=azure-devops-rest-7.1&tabs=HTTP#uri-parameters

    Alternatively, when you're running a WIQL to fetch work items and the query is likely to return more than 20k items, you would have to partition your query into batches and get details accordingly.

    If your item set is very large, consider the Analytics OData feed. It’s built for reporting and supports server-side paging beyond 10k via @odata.nextLink ($skip/$skiptoken)—ideal for pulling very large datasets into Power BI or code. See https://learn.microsoft.com/en-us/azure/devops/report/extend-analytics/odata-query-guidelines?view=azure-devops

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.