Member-only story
Add users to Azure DevOps Team and set as Administrator by REST API
When using the Azure DevOps REST API to create Teams and add users, you may want to set the administrators as well at the same time. However, this REST API is not well documented on the Microsoft documentation site. With some searching and mapping of resources, I have below the method on how to add users to an Azure DevOps team then set them as an Administrator.
Assumptions
During this post there is going to be some assumption through the code, as all of them will be using the REST API and authenticating in the same way.
Authentication
When Authenticating with the API we are going to use a Basic
authentication, which is using a Personal Access Token(PAT). This can be generated by an Azure DevOps user, or if using this through a pipeline, you can use the System.AccessToken
variable. With this token we will encrypt it in the correct format using the below PowerShell code. The $user
can be any text and is used for the formatting of the access token. This token will be used throughout the API calls.
$user = "[anything]"
$accessToken = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $PersonalAccessToken)))
Code Formatting
We will also have a standard format to all the API requests and the code on how we request them. Following the underlined components below, we will have: