Azure DevOps REST API调用仅检索前100条记录,而ContinuationToken获取为空 [英] Azure DevOps REST API call retrieving only top 100 records and ContinuationToken getting as null

查看:51
本文介绍了Azure DevOps REST API调用仅检索前100条记录,而ContinuationToken获取为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的API调用来检索所有的CouldTests(1000+ cloudtests),但是它仅返回100条记录.在下面的代码中,ContinuationToken变为null.这里有什么问题吗?我尝试做..虽然也,但没有区别.任何帮助表示赞赏.预先感谢

I am using the below API call for retrieving all the CouldTests(1000+ cloudtests), but it is returning only 100 records. Here in the below code ContinuationToken is getting as null. Anything wrong here? I tried do..while also, but no difference. Any help is appreciated. Thanks in advance

$personalAccessToken = "Token"
$auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)"))

$headers = @{}
$headers.Add("Authorization", "Basic $auth")
$Today = Get-Date -Format "yyyy-MM-dd"
$Tomorrow = (Get-Date).AddDays(1).ToString("yyyy-MM-dd")

do
{
    $uri = "https://{instance}/{collection}/{project}/_apis/test/runs?minLastUpdatedDate=$Today&maxLastUpdatedDate=$Tomorrow&releaseIds=12345678&continuationToken=$ContinuationToken&includeRunDetails=true&api-version=5.0"

    $TestRuns = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get -ContentType "application/json" 
    $continuationToken = $TestRuns.Headers.'x-ms-continuationtoken'
    $Tests += $TestRuns
}
while ($continuationToken -ne $null)

推荐答案

您应该使用 Invoke-WebRequest 而不是 Invoke-RestMethod 来获得它:

You should get it with Invoke-WebRequest and not with Invoke-RestMethod:

do
{
    $uri = "https://{instance}/{collection}/{project}/_apis/test/runs?minLastUpdatedDate=$Today&maxLastUpdatedDate=$Tomorrow&releaseIds=12345678&continuationToken=$ContinuationToken&includeRunDetails=true&api-version=5.0"

    $TestRuns = Invoke-WebRequest -Uri $uri -Headers $headers -Method Get -ContentType "application/json" 
    $continuationToken = $TestRuns.Headers.'x-ms-continuationtoken'
    $Tests += $TestRuns
}
while ($continuationToken -ne $null)

这篇关于Azure DevOps REST API调用仅检索前100条记录,而ContinuationToken获取为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆