How add administrator to team in Azure DevOps using SDK or Web Api?

I try to create a team using SDK. And it creates it without any members and administrators:

WebApiTeam team = new WebApiTeam
        {
            Name = "New Team",
            ProjectId = project.Id
        };

then call

public virtual Task<WebApiTeam> CreateTeamAsync(WebApiTeam team, string projectId, object userState = null, CancellationToken cancellationToken = default);

And as a result, I have a team with the name "New Team" without any members and admins. Then i add members into team:

public Task<bool> AddMemberToGroupAsync(IdentityDescriptor containerId, Guid memberId, object userState = null, CancellationToken cancellationToken = default);
containerId = myNewTeam.id;
memberId=(user || group).id;

but how to add admins into team idk. I found that when we do this manually it call

http://{baseUrl}/tfs/{project}/{teamId}/_api/_identity/AddTeamAdmins?__v=5

I try to call this using postman but I can't authorize. Does anyone know how I can solve this issue?

Upvotes: 1

Views: 972

Answers (2)

Hugh Lin
Hugh Lin

Reputation: 19471

If you are using tfs, you need to note that the Azure DevOps Command Line Interface (CLI) is available for Azure DevOps Server 2020 and Azure DevOps Services. This is stated here.

I try to call this using postman but I can't authorize

You need to use PAT with full scopes for certification.

enter image description here

Here is my test:

enter image description here

Upvotes: 1

Joey Cai
Joey Cai

Reputation: 20127

You can do it by assigning the users the correct permissions on the team's security namespace. Here's an example that adds two users as admins to a new team.

$myOrg = "https://dev.azure.com/myOrg/"
$newTeam = "My New Team"
$newAdmin = "[email protected]"
$myProject = "My Project"

az login

$team = az devops team create --name $newTeam --org $myOrg --project $myProject | ConvertFrom-Json

$user = az devops user show --user $newAdmin  --organization $myOrg | ConvertFrom-Json
az devops security group membership add --group-id $team.identity.subjectDescriptor --member-id $user.user.descriptor --org $myOrg
az devops security permission update --id "5a27515b-ccd7-42c9-84f1-54c998f03866" --subject $user.user.principalName --token "$($team.projectId)\$($team.id)" --allow-bit 31  --org $myOrg

Upvotes: 1

Related Questions