RestApi获取VSTS中测试用例的附件详细信息

时间:2018-10-03 10:48:15

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

我想使用restapi从VSTS中获取附件详细信息和测试用例的附件。

5.0中的哪个restapi可用于检索附件详细信息?

https://docs.microsoft.com/en-us/rest/api/vsts/?view=vsts-rest-5.0

enter image description here

我创建了一个PBI,添加了2个任务和2个测试,如下所示:

ID字段是WORKITEMID吗?

图1:

enter image description here

图2:

enter image description here

1 个答案:

答案 0 :(得分:1)

测试用例是一种工作项类型,因此您可以使用Attachments - Get REST API。

下载附件:

GET https://dev.azure.com/{organization}/{project}/_apis/wit/attachments/{id}?api-version=5.0-preview.3

要获取attachment id,可以将Get Work Item API与$expand=al一起使用:

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

您将在结果中获得ID(在url部分的relations中):

"relations":[
     {
       "rel":"AttachedFile",
       "url":"https://shaykia.visualstudio.com/_apis/wit/attachments/xxxxx-4453-40b0-acaf-ace14902484c",

所以现在您有了附件ID:xxxxx-4453-40b0-acaf-ace14902484c,要使用上面的API(instaed)下载附件:

https://dev.azure.com/{organization}/{project}/_apis/wit/attachments/xxxxx-4453-40b0-acaf-ace14902484c?api-version=5.0-preview.3