【问题标题】:How I can get attachments detail for my workitem using Azure DevOps Rest API如何使用 Azure DevOps Rest API 获取工作项的附件详细信息
【发布时间】:2019-11-21 22:09:45
【问题描述】:

我正在尝试获取针对我的工作项的附件列表以及我需要的附件数量、附件名称。附在我的工作项目上。我尝试阅读 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 端点来获取 worktiem 的附件详细信息。

【问题讨论】:

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


    【解决方案1】:

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

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

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

    $expand=all
    

    现在在结果中你会得到relations属性,在那里你会找到附件的url,在url中你可以找到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下载附件了。

    【讨论】:

    • 谢谢,$expand=all 使用此参数开始返回附件名称。它完成了。谢谢。
    猜你喜欢
    • 2021-09-09
    • 2019-11-12
    • 2020-04-05
    • 1970-01-01
    • 2021-10-19
    • 2016-11-26
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    相关资源
    最近更新 更多