且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Azure DevOps Rest API获取工作项的附件详细信息

更新时间:2022-12-07 11:46:22

您应该首先使用

You should first to get the work item details with Work Items - Get Work Item Rest API:

GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}

注意:要获取附件的详细信息,您需要将其添加到URL参数中:

Note: to get the attachments details you need to add this to parameter the url:

$expand=all

现在,在结果中您将获得relations属性,在这里您将找到附件的网址,在该网址中您可以找到ID.

Now in the results you will get the relations property, there you will find the attachments url, in the url you can find the id.

例如:

$url = https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/434?$expand=all&api-version=5.0

$workItem = Invoke-RestMethod -Uri $url -Method Get -ContentType application/json

$split = ($workitem.relations.url).Split('/')

$attachmentId = $split[$split.count - 1]

# Result: 1244nhsfs-ff3f-25gg-j64t-fahs23vfs

现在您可以使用附件api下载附件.

Now you can use the attachment api to download the attachment.