0

I'm creating a azure function which makes use of get GetTestRunsAsync() to retrieve all Test runs from azure devops organisation.But the function does not support continuation token. Is there a way to get continuation token for getting all test runs using azure devops rest api in C#?

GET https://dev.azure.com/{organization}/{project}/_apis/test/runs?api-version=6.0

1 Answers1

1

Please check with Runs - Query - REST API (Azure DevOps Test) | Microsoft Docs Where it seems the continuation token can be as optional parameter.

Please check the Azure DevOps API calls have got an x-ms-continuationtoken value in HTTP response headers. Generally, the continuationToken to load the second page is on the response body of the first page, and so on.

First please check if you have continuation token in headers with normal request url :

GET https://dev.azure.com/{organization}/{project}/_apis/test/runs?minLastUpdatedDate={minLastUpdatedDate}&maxLastUpdatedDate={maxLastUpdatedDate}&api-version=6.0

Please note that no continuationToken received from previous batch or null for first batch. If there is has other than first batch list continuation token may appear to list for next batches .Generally, the continuationToken to load the second page is on the response body of the first page, and so on. It is not supposed to be created if it is received from last batch by user.

Example for users: snippet from this blog

var requestUrl = $"https://vssps.dev.azure.com/{OrganizationName}/_apis/graph/users?api-version=6.0-preview.1";

    var response = await client.GetAsync(requestUrl);

var headers = response.Headers;
    string continuationToken = null;

    if (headers.Contains(Header_ContinuationToken) == true)
    {
        Logger.LogInfo("** CONTINUATION TOKEN **");
        continuationToken = response.Headers.GetValues(Header_ContinuationToken).FirstOrDefault();
 ...
    }

Then you may use one of the following requesturls by adding the token to the url

Var requesturl =$”https://dev.azure.com/{organization}/{project}/_apis/test/runs?continuationToken={continuationToken}&api-version=6.0”

(or)

https://dev.azure.com/{organization}/{project}/_apis/test/runs?api-version=6.0-preview.1&continuationToken={continuationToken}";

and call that request url something like GetAsync(requestUrl);

References:

  1. Azure DevOps API Continuation Tokens (benday.com)
  2. powershell - Azure DevOps Rest Api to get all projects with continuation token - Stack Overflow
kavyaS
  • 8,026
  • 1
  • 7
  • 19