如何为使用Microsoft Graph API的团队设置电子邮件?

时间:2020-07-17 18:02:09

标签: microsoft-graph-api microsoft-teams graph-api-explorer

我们正在创建一个团队组(使用beta Graph API),我们希望电子邮件地址包含另一个值,而不是基于displayName中提供的值。

在搜索文档时,似乎可以通过在mailNicknamehttps://docs.microsoft.com/en-us/graph/teams-create-group-and-team)中为AdditionalData提供一个值来实现。

所以我实现了。不幸的是,邮件地址和别名仍然像TestGroup@domain.nl而不是TestMailNickname@domain.nl

var graphApiServiceClient = new GraphServiceClient(this.authenticationProvider)
{
    BaseUrl = "https://graph.microsoft.com/beta"
};

var owner = "valueForOwner";
var teamTemplate = teamTemplateType == TeamTemplateType.Staff
    ? "educationStaff"
    : "educationClass";

var team = new Team
{
    AdditionalData = new Dictionary<string, object>
    {
        { "template@odata.bind", $"https://graph.microsoft.com/beta/teamsTemplates('{teamTemplate}')" },
        { "owners@odata.bind", new[]{$"https://graph.microsoft.com/beta/users('{owner}')"}},
        { "displayName", "TestGroup" },
        { "description", "This is a testgroup" },
        { "mailNickname", "TestMailNickname" }
    }
};

await graphApiServiceClient.Teams.Request().AddAsync(team);

之后,我使用MailNickname之类的更新请求来更新MailNickname属性时,await graphApiServiceClient.Groups[objectId].Request().UpdateAsync(new Group { MailNickname = mailNickname}); 会发生更改。

通过graphApiServiceClient.Groups[objectId].Request().GetAsync()

确认

不幸的是,它仍然以https://admin.microsoft.com/AdminPortal/Home#/groups的身份显示TestGroup@domain.nl作为管理员的别名。

但是,对于Mail属性,像这样更新值不起作用,因为它声明更新请求中为只读。

有人知道我在原始的创建/添加请求中做错了什么吗?

另外,有人知道为什么仍显示旧别名值而不是https://admin.microsoft.com/AdminPortal/Home#/groups上更新的别名吗?

1 个答案:

答案 0 :(得分:0)

这可以通过首先通过Graph API创建一个组,然后使用组ID为该组创建团队来实现。

通过“ https://graph.microsoft.com/v1.0/groups”创建组。

 {  
    "displayName": "TestGroup",  
    "mailNickname": "TestMailNickname",  
    "mailEnabled": true,  
    "securityEnabled": false,  
    "description": "This is a testgroup",  
    "groupTypes": [  
        "Unified"  
    ],  
    "owners@odata.bind": [  
        "https://graph.microsoft.com/v1.0/users/OWNEDID"  
    ]  
} 

创建该组后,它将输出一个ID,您将使用该ID通过“ https://graph.microsoft.com/v1.0/groups/YOURIDHERE/team”创建一个团队

身体看起来像;

{  
    "memberSettings": {  
        "allowCreateUpdateChannels": false,
        "allowAddRemoveApps": false,
        "allowCreateUpdateRemoveTabs": false,
        "allowCreateUpdateRemoveConnectors": false  
    }
}