PedroC88
PedroC88

Reputation: 3829

HTTP Request to find work item by custom field in Azure DevOps

Is there a way to find all work items, through an HTTP request, where the value of a custom field is equal to a given value?

I have a PowerAutomate flow that creates tickets when a new email is received in a specific email account. The issue that whenever someone replies to the thread that creates duplicate tickets. My idea to solve it was to create a new field called Email ID, set it during the creation of the ticket and then, at the beginning of the flow, check if there's a work item already with the same conversation ID.

I just couldn't find any action that allowed me to search for the work item in that way, except for maybe the HTTP Request.

Upvotes: 2

Views: 1708

Answers (1)

Jane Ma-MSFT
Jane Ma-MSFT

Reputation: 5242

You can use the following REST API:

POST https://dev.azure.com/{organization}/_apis/Contribution/dataProviders/query?api-version=5.1-preview.1

Here is an example of request body:

{
    "contributionIds": [
        "ms.vss-work-web.work-item-query-data-provider"
    ],
    "context": {
        "properties": {
            "wiql": "SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = @project AND [Custom.EmailId] = '{email id}'",
            "sourcePage": {
                "routeValues": {
                    "project": "{project}"
                }
            }
        }
    }
}

In the response body, if there are work items in query result, the ids of work items will be present in data.ms.vss-work-web.work-item-query-data-provider.data.targetIds. And if there is no work item, the variable data.ms.vss-work-web.work-item-query-data-provider.data.targetIds is empty.

Upvotes: 1

Related Questions