Search code examples
azure-devopsazure-devops-rest-api

Azure DevOps API to add a user or group as a admin for a team


I am trying to use the API to add a user (or another group) as an admin for a team.

I am able to use the API to create a team, create groups, create areas & iterations however I can seem to add a user as an admin for the team.

Has anyone been able to do this using the API?


Solution

  • To add member of current Organization to Project Administrator you should use:

    Memberships - Add: PUT (application/json)

    https://vssps.dev.azure.com/{organization}/_apis/graph/memberships/{subjectDescriptor}/{containerDescriptor}?api-version=5.1-preview.1

    1.subjectDescriptor: A descriptor to a group or user that can be the child subject in the relationship.

    2.containerDescriptor: A descriptor to a group that can be the container in the relationship.

    Note:

    Values of subjectDescriptor and containerDescriptor are hard to get, so I'm not sure if it meets your requirements in your specific scenario.

    We have to fetch the subjectDescriptor (represent user) and containerDescriptor (represent ProjectAdmin of one project) before you use Memberships-Add api. For me:

    I use Users-List to list all the details about Users in Collection to get the Descriptor of one user:

    enter image description here

    And use Groups-List to list all the groups to get the Descriptor of Project Admin of one project:

    enter image description here

    Then use MemberShips-Add to add the user to project RequireCheck's Project Administrator group. Once we get the 201-created, we can see the change in web portal after refreshing the page. (Sometimes it has one minute delay.)

    Update: Another direction you can check this ticket.