문제

How to create “Office 365 Group” and assign user to that group using MS Graph API?

도움이 되었습니까?

해결책

Check below for sample code to create Office 365 group and add user to this group using MS Graph API:

var newGroupName = "TestGroup";
var newGroupMailNickname = "TestGroup";
var userEmail = "userEmail";
var group = new Microsoft.Graph.Group
{                        
    DisplayName = newGroupName,
    GroupTypes = new List<String>()
        {
            "Unified"
        },
    MailEnabled = true,
    MailNickname = newGroupMailNickname,
    Description = "Group Description",
    SecurityEnabled = false
};

var createdGroup = _graphServiceClient.Groups
    .Request()
    .AddAsync(group).GetAwaiter().GetResult();

Microsoft.Graph.User userToAdd = _graphServiceClient.Users[userEmail].Request().GetAsync().GetAwaiter().GetResult();                    
_graphServiceClient.Groups[createdGroup.Id].Members.References.Request().AddAsync(userToAdd);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top