Azure Devops Rest API仅返回100个项目 [英] Azure devops rest api returns only 100 projects

查看:56
本文介绍了Azure Devops Rest API仅返回100个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的组织中检索所有项目我有300个项目,但api调用仅返回100

我尝试将$ top与api结合使用,但它什么也不返回

这是我的脚本,用于获取100个项目并转换为csv文件,但是我需要此csv文件中所有300个项目的详细信息-

  connectionToken ="$ BaseUrl =" https://dev.azure.com/{organization_name}/_apis/projects?api-版本= 5.0";$ base64AuthInfo =[System.Convert] :: ToBase64String([System.Text.Encoding] :: ASCII.GetBytes(:$($ connectionToken)"))$ ProjectInfo = Invoke-RestMethod -Uri $ BaseUrl -Headers @ {authorization =" Basic $ base64AuthInfo"}-方法Get$ ProjectDetails = $ ProjectInfo |ConvertTo-Json-深度100 |外档"/list.json"$ ProjectList =获取内容"/list.json"-原始ConvertFromJson |选择 -扩大价值|导出CSV"list.csv" 

我也尝试使用invoke-webrequest,它也不会返回任何内容

谢谢

解决方案

Azure devops rest api仅返回100个项目

答案是使用指定的 $ top 参数.

但是在powershell中使用此参数时,我们需要注意使用`(而不是& ;.)转义 $ .

那是因为在powershell中,无论如何,单引号''仅表示引号内的字符.换句话说,单引号内的内容不会替代变量和转义字符.用双引号"" 允许变量替换和字符转义.

当您在 BaseUrl 中使用双引号时:

  $ BaseUrl ="https://dev.azure.com/{organization_name}/_apis/projects?api-versions=5.0" 

如果在该URL中添加 $ top = 300 而不是& ,则需要转义字符 $ .

因此, BaseUrl 应该是:

  $ BaseUrl ="https://dev.azure.com/{organization_name}/_apis/projects?`$top=300&api-version=5.0" 

或者您可以在URL中使用单引号:

  $ BaseUrl ='https://dev.azure.com/{organization_name}/_apis/projects?$top=300&api-version=5.0' 

检查文档

I am trying to retrieve all projects from my organizations I have 300 projects but api call returns only 100

I tried using $top with api then it returns nothing

Here is my script which works for getting 100 projects and converting to csv file but I need details of all 300 projects in this csv file -

connectionToken = ""
$BaseUrl = "https://dev.azure.com/{organization_name}/_apis/projects?api- 
versions=5.0"
$base64AuthInfo = 
[System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes
(":$($connectionToken)"))

$ProjectInfo = Invoke-RestMethod -Uri $BaseUrl -Headers @{authorization = 
"Basic $base64AuthInfo"} - Method Get

$ProjectDetails = $ProjectInfo | ConvertTo-Json -Depth 100 | out-file 
"/list.json"

$ProjectList = Get-Content "/list.json" -Raw | ConvertFromJson | select - 
Expand value | Export-CSV "list.csv"

I also tried using invoke-webrequest it also returns nothing

Thank you

解决方案

Azure devops rest api returns only 100 projects

The answer is use a specify $top parameter.

But when using this parameter in powershell, we need to be careful to escape the $ by ` instead of &.

That's because in powershell, single quotation '' marks only represent the characters within the quotation marks in any case. In other words, the content within single quotes will not be substituted for variables and escaped characters. In double quotes "", variable substitution and character escaping are allowed.

When you use the double quotes with the BaseUrl

$BaseUrl = "https://dev.azure.com/{organization_name}/_apis/projects?api-versions=5.0"

We need escape character $ if we add $top=300 instead of & in that URL.

So, the BaseUrl should be:

$BaseUrl = "https://dev.azure.com/{organization_name}/_apis/projects?`$top=300&api-version=5.0"

Or you could use single quotation for the URL:

$BaseUrl = 'https://dev.azure.com/{organization_name}/_apis/projects?$top=300&api-version=5.0'

Check the document Escaping in PowerShell

The PowerShell escape character is the backtick "`" character.

Below is my test result:

这篇关于Azure Devops Rest API仅返回100个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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