Odata.bind 使用 Microsoft Graph 创建团队时出错

Odata.bind error when creating a team with microsoft graph

我正在使用带有 .net 核心的 miscrosoft graph 在 Microsoft Teams 中创建一个团队。但是当我发送创建团队的请求时,我总是收到一条错误消息:

Invalid bind property name template in request.

为此,我遵循了此处文档中要求的步骤:https://docs.microsoft.com/en-us/graph/api/team-post?view=graph-rest-beta&tabs=csharp#example-4-create-a-team-from-group

我已经尝试了 Microsoft 文档中的大量示例,来自 v1.0 和 beta 版。

我创建的群组是这样的:

        {
            var email = groupName.ToLower().Replace(" ", "_");
            //Create a new object group
            Group group = new Group
            {
                DisplayName = groupName,
                GroupTypes = new List<string>()
                {
                    "Unified",
                },
                MailEnabled = true,
                MailNickname = email,
                SecurityEnabled = false,
                AdditionalData = additionnalData,
            };

附加数据为:

           var additionalData = new Dictionary<string, object>()
            {
                {"members@odata.bind", new List<string>()},
                {"owners@odata.bind", new List<string>()}
            };
            (additionalData["members@odata.bind"] as List<string>).Add(TeamsApi.GetUserOData(ownerEmail));
            (additionalData["owners@odata.bind"] as List<string>).Add(TeamsApi.GetUserOData(ownerEmail));

我的团队创作是这样的:

            Team team = new Team
            {
                AdditionalData = new Dictionary<string, object>()
                {
                    {"group@odata.bind",$"https://graph.microsoft.com/v1.0/groups({newGroupId})"},
                    {"template@odata.bind","https://graph.microsoft.com/beta/teamsTemplates('standard')"},
                },

            };
            return await GraphClient.Groups[newGroupId].Team.Request().PutAsync(team);

所以这是我的问题:我做错了什么?是语法错误吗?我在哪里可以找到关于 Odata.bind?

的文档

我用这个 post

解决了我的问题

我给创建的每个对象都放了一个属性 ODataType = null

Team team = new Team
{
    ODataType = null,
    Channels = new TeamChannelsCollectionPage(),
};

Channel general = new Channel
{
    DisplayName = "Général",
    ODataType = null
};

team.Channels.Add(general);

return await GraphClient.Groups[newGroupId].Team.Request().PutAsync(team);