执行VSTS查询并使用API​​获取其所有详细信息

时间:2020-05-15 07:28:00

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

我在共享文件夹下创建了VSTS查询。但是,当我尝试列出我的域下的所有查询时,该文件夹中没有任何显示。该文件夹名称显示在该JSON响应中。但是该文件夹下的实际查询没有显示。

这是我尝试列出所有查询的方式

https://dev.azure.com/{org}/{projectid}/_apis/wit/queries?api-version=4.1

但是它只是列出了最上面的文件夹。我需要列出该项目下的所有查询

接下来的主要问题是一旦我有了一个API ID,并且在执行它时,仅给了我工作项ID和URL。我没有得到任何细节,例如其任务或错误或特定信息

这是我尝试的方式

https://dev.azure.com/{org}/{proj}/_apis/wit/wiql/{wiqlid}?api-version=5.0&$expand=all

请帮助我解决这两个问题。

1 个答案:

答案 0 :(得分:2)

您可以尝试使用depth参数吗?

在查询文件夹中,将子查询和文件夹返回到该深度。

如果执行此操作,则会大声地在子级集合中查询。

https://dev.azure.com/thecodemanual/DevOps Manual/_apis/wit/queries?$expand=all&$depth=2&api-version=5.1

如果您的查询位于子文件夹中,则可能会对您有所帮助。

当我运行wiql时,我得到了:

https://dev.azure.com/thecodemanual/DevOps Manual/DevOps Manual Team/_apis/wit/wiql/91dad662-7104-4882-b28f-945c152fc4ee?api-version=5.1
{
    "queryType": "flat",
    "queryResultType": "workItem",
    "asOf": "2020-05-15T10:12:01.163Z",
    "columns": [
        {
            "referenceName": "System.Id",
            "name": "ID",
            "url": "https://dev.azure.com/thecodemanual/_apis/wit/fields/System.Id"
        },
        {
            "referenceName": "System.WorkItemType",
            "name": "Work Item Type",
            "url": "https://dev.azure.com/thecodemanual/_apis/wit/fields/System.WorkItemType"
        },
        {
            "referenceName": "System.Title",
            "name": "Title",
            "url": "https://dev.azure.com/thecodemanual/_apis/wit/fields/System.Title"
        },
        {
            "referenceName": "System.State",
            "name": "State",
            "url": "https://dev.azure.com/thecodemanual/_apis/wit/fields/System.State"
        },
        {
            "referenceName": "System.AreaPath",
            "name": "Area Path",
            "url": "https://dev.azure.com/thecodemanual/_apis/wit/fields/System.AreaPath"
        },
        {
            "referenceName": "System.IterationPath",
            "name": "Iteration Path",
            "url": "https://dev.azure.com/thecodemanual/_apis/wit/fields/System.IterationPath"
        },
        {
            "referenceName": "System.Tags",
            "name": "Tags",
            "url": "https://dev.azure.com/thecodemanual/_apis/wit/fields/System.Tags"
        }
    ],
    "sortColumns": [
        {
            "field": {
                "referenceName": "System.ChangedDate",
                "name": "Changed Date",
                "url": "https://dev.azure.com/thecodemanual/_apis/wit/fields/System.ChangedDate"
            },
            "descending": true
        }
    ],
    "workItems": []
}

这是后面运行的wiql查询:

select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] 
from Workitems 
where [System.TeamProject] = @project and [System.WorkItemType] <> '' and [System.State] <> ''

这是你想要的吗?

编辑

您在这里惹恼了

https://dev.azure.com/{org}/{proj}/_apis/wit/wiql/{wiqlid}?api-version=5.0&$expand=all

请在team之后添加proj

https://dev.azure.com/{org}/{proj}/{team}/_apis/wit/wiql/{wiqlid}?api-version=5.0&$expand=all

{team}