【问题标题】:RestApi to get attachment details for a testcase in VSTSRest Api 以获取 VSTS 中测试用例的附件详细信息
【发布时间】:2018-10-10 19:57:38
【问题描述】:

我想使用restapi从VSTS获取附件详细信息和附件。

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

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

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

ID 字段是 WORKITEMID 吗?

图一:

图2:

【问题讨论】:

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


    【解决方案1】:

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

    下载附件:

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

    要获取attachment id,您可以使用带有$expand=al 的Get Work Item API:

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

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

    "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
    

    【讨论】:

    • 感谢@shayki 的回复。我可以从哪里获取附件 ID?
    • 测试用例 ID 是否作为 WorkItemID 传递?
    • 我不确定我是否理解这个问题,请查看我的更新。
    • dev.azure.com{organization}/{project}/_apis/wit/workitems/{workItemID}?api-version=5.0&$expand=all... 对于这个 restapi,测试用例 id 是工作项ID?我在哪里可以找到 workitemid?
    • 是工作项ID,每个工作项都有ID,打开一个工作项,在类型(Test,Bug,Epic)附近会看到一个数字,就是ID。
    猜你喜欢
    • 2020-07-21
    • 2019-11-21
    • 2017-07-06
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多