'How to get Pull Requests associated with a Work Item via the Azure DevOps API
I am trying to list all Pull Requests associated with a Work Item but according to the Work Items API there doesn't seem to be a way to get it:
GET https://dev.azure.com/{org}/{project}/_apis/build/builds/123456/workitems?api-version=6.0
The above returns list of work items, such as:
{
"count": 40,
"value": [
{
"id": "156267",
"url": "https://dev.azure.com/xxx/_apis/wit/workItems/12345"
},
...
]
}
Now, if I still decide to query each returned work item I still don't see a Pull Request. For example:
GET https://dev.azure.com/xxx/_apis/wit/workItems/12345
The above returns a JSON object about updates done to the workitem, but this can be a commit, state update or comments.
Is there a way to get a list of PRs per work item?
Thanks
Solution 1:[1]
You need to add &$expand=relations
:
GET https://dev.azure.com/xxx/_apis/wit/workItems/12345?$expand=relations
Now in the response you will get the linked PR under the relations
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |