Zam
Zam

Reputation: 1388

Azure DevOps get commits linked to a work item via the REST API

Is there a way to get Git Commits that are linked to a work item given only the work item ID?

enter image description here

I'm using PowerShell and this URI to get work items, but I don't see any of the linked commits on the returned object. I also don't see any documentation on how to get these links.

$Results = Invoke-RestMethod -Uri "http://azuredevops/azuredevops/Collection/Project/_apis/wit/workitems?api-version=5.1&ids=1" -Method "GET" -UseDefaultCredentials | Select-Object -ExpandProperty Value
$Results.fields

Upvotes: 5

Views: 3025

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 19026

You are very close to the correct solution.

The commits which linked to the work item is relation of work item. So, here, you need to specify $expand in API to get the corresponding commits content.

Get https://dev.azure.com/{org name}/{project name}/_apis/wit/workitems/{id}?$expand=relations&api-version=5.1

Then you would see the commits in relations part of the response body:

enter image description here

Upvotes: 10

Related Questions