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

时间:2019-07-12 07:14:00

标签: azure-devops azure-devops-rest-api

我正在尝试根据我的工作项目获取附件列表以及所需的附件数量,附件名称。这些都附在我的工作项目上。我试图阅读Azure DevOps的文档,可以看到以下内容

https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/attachments?view=azure-devops-rest-5.0

它具有Get,Create和List端点可用。但是要获取它,要求提供的附件ID不可用,因为没有端点返回附件详细信息。

您能指导我使用哪个API端点来获取工作附件的附件详细信息。

1 个答案:

答案 0 :(得分:0)

您应该首先使用Work Items - Get Work Item Rest API获取工作项详细信息:

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

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

$expand=all

现在,在结果中您将获得relations属性,在这里您将找到附件的网址,在该网址中您可以找到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下载附件。