对 Azure DevOps API 进行分页

问题描述 投票:0回答:1

我有兴趣了解 Azure DevOps API 中是否有可用的分页功能,专门用于使用以下端点列出项目的存储库:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=7.1-preview.1

不幸的是,根据文档,列出存储库时似乎不支持分页。

azure azure-devops azure-devops-rest-api
1个回答
0
投票

您可以尝试以下 API 请求来获取分页输出,同时列出存储库:-

我的 API 带有顶级参数:-

https://dev.azure.com/sid24desai0738/AzureDevops/_apis/git/repositories?api-version=7.1-preview.1&$top=100

我的 API 带有顶部和跳过参数:-

https://dev.azure.com/orgName/ProjName/_apis/git/repositories?api-version=7.1-preview.1&$top=10&$skip=10

Powershell 请求:-

$PAT = "xxxxxrp36cuhakncvsamfbukleq"
$OrgName = "orgname"
$ProjectName = "projecetname"
$ApiVersion = "7.0"

$services = Invoke-RestMethod -Uri "https://dev.azure.com/orgName/ProjName/_apis/git/repositories?api-version=7.1-preview.1&$top=10&$skip=10" -Method Get -Headers @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}

$services.value

输出:-

enter image description here

参考:-

Azure-devops rest api - 分页和速率限制 - Thinbug

© www.soinside.com 2019 - 2024. All rights reserved.