Created
April 9, 2022 07:49
-
-
Save MahdiKarimipour/caa51c854b01a9a9404015f18d2b3645 to your computer and use it in GitHub Desktop.
Create Security Group using Azure DevOps REST APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<(GroupViewModel, HttpStatusCode)> CreateGroup(GroupViewModel group, string scopeDescriptor) | |
{ | |
var request = new AzureDevOpsCreateGroupRequestDto() | |
{ | |
displayName = group.Name, | |
description = group.Description | |
}; | |
var url = appSettings.AzureDevOpsSettings.CreateGroupUrl | |
.Replace("{organisation}", group.Organisation) | |
.Replace("{scopeDescriptor}", scopeDescriptor); | |
var (result, response) = await apiCall.PostAsync<AzureDevOpsCreateGroupResponseDto>( | |
url: url, | |
body: request, | |
password: appSecrets.AzureDevOpsToken); | |
if (result.IsEmpty()) | |
{ | |
return (null, response.StatusCode); | |
} | |
var groups = await GetAllGroups(group.Organisation); | |
var createdGroup = groups.FirstOrDefault(g => g.PrincipalName == $"[{group.Project}]\\{group.Name}"); | |
return (createdGroup, HttpStatusCode.OK); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment