Azure DevOps REST API and the continuation token
I have become a fan of using the az devops cli for managing many Azure DevOps Services from the command line but it also has some limitations. Up till now there isn’t any support for connecting with Azure Test Plans.
The Azure DevOps cli extension only adds support for devops
, pipelines
, artifacts
, boards
, and repos
.
So, switching back to use the Azure DevOps REST API for managing Azure Test Plans.
In one of my recent assignments I was tasked to provide a general Excel report that gives a Test Result overview of a variable Test Plan. No big deal I thought and I was quickly able to come up with the results using the following REST API calls:
Great! Let’s automate the full solution via a pipeline and done!
Quickly I got feedback that for some Test Plans the results were incomplete and that’s the point where I realized that some of the REST API call didn’t return all results at once. Doing some debugging and digging into the documentation I noticed that the call for getting all test cases from a test suite was limited to 200 results and a continuation token was passed as a response for getting more results in a next call.
If the list of test cases returned is not complete, a continuation token to query next batch of test cases is included in the response header as “x-ms-continuationtoken”. Omit this parameter to get the first batch of test cases.
All clear but it took me quite a bit to implement this correctly and that’s why I want to document and share this for future usage.
While invoking the first REST API call I’m using the ResponseHeadersVariable property to inspect a potential continuation token. If that token is present I will need to adapt the query string for the next call and include this token properly.
Important: the value of the ResponseHeadersVariable in the Invoke-RestMethod must be a variable name without the dollar sign ($).