如何使用Azure DevOps Rest API获取工作项的附件详细信息 [英] How I can get attachments detail for my workitem using Azure DevOps Rest API

查看:258
本文介绍了如何使用Azure DevOps Rest API获取工作项的附件详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to get the list of the attachments against my workitem along with that I need, attachment count, attachments name. which are attached to my workitem. I tried to read the documentation of Azure DevOps I can see the following

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

它具有获取",创建"和列表"端点可用.但是要获取它,要求提供的附件ID不可用,因为没有端点返回附件详细信息.

It has Get, Create and List endpoints available. But to get it asks for the attachment ID which not available because no endpoint returns the attachment details.

能否请您指导我使用哪个API端点来获取Worktiem的附件详细信息.

Can you please guide me which API endpoint I can use to get the attachment details of a worktiem.

推荐答案

您应该首先使用

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.

这篇关于如何使用Azure DevOps Rest API获取工作项的附件详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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