james
james

Reputation: 647

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?

Upvotes: 1

Views: 4338

Answers (2)

Tom
Tom

Reputation: 958

It looks like there is now a more convenient way to add a user as project administrator using the entitlements api:

  • First do a request to get the Project ID: GET https://dev.azure.com/{organisation}/_apis/projects/{projectname}?api-version=5.0

Then use the id from this response to call this API:

POST https://vsaex.dev.azure.com/{organization}/_apis/userentitlements?api-version=7.0

{
  "accessLevel": {
    "accountLicenseType": "express"
  },
  "extensions": [
    {
      "id": "ms.feed"
    }
  ],
  "user": {
    "principalName": "{user email}",
    "subjectKind": "user"
  },
  "projectEntitlements": [
    {
      "group": {
        "groupType": "ProjectAdministrator"
      },
      "projectRef": {
        "id": "{project id}"
      }
    }
  ]
}

Of course make sure the API is called with the correct permissions.

Upvotes: 2

LoLance
LoLance

Reputation: 28216

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.

Upvotes: 2

Related Questions