How to get the teams that a user belongs to using Azure Devops REST API?

Viewed 23

I am trying to find how to retrieve a list of teams that a user belongs to from a work item created in Azure DevOps. From the documentation I can't figure out if there is a way to retrieve the teams a user belongs to from the users userId, descriptor or displayName.

Just to clarify I am looking to obtain the teams from the Azure DevOps organisation/project that are located in the project setting menu.

1 Answers

Yes, you can.

But the REST API will not tell you directly that the user belongs to, it will tell you the descriptor of the group.

I will provide the detailed steps to get the information you want here.

1, List Users to capture all of the descriptor of the users.

https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/users/list?view=azure-devops-rest-6.0&tabs=HTTP

2, Use the user's descriptor to get the User information content.

https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/users/get?view=azure-devops-rest-6.0&tabs=HTTP

The response like below:

enter image description here

Sending a request to the box-selected data can get what group the user belongs to(This can only get the descriptor.).

3, Use the below API and compare to the descriptor you get from the above, you can get the name of all the groups that the user belongs to.

https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/groups/list?view=azure-devops-rest-6.0&tabs=HTTP

Related