Odata.bind error when creating a team with microsoft graph

僤鯓⒐⒋嵵緔 提交于 2020-12-15 05:15:12

问题


I'm using miscrosoft graph with .net core to create a team in Microsoft Teams. But when I send the request for the team creation I always get an error message:

Invalid bind property name template in request.

To do that, I followed the step required in the documentation here: https://docs.microsoft.com/en-us/graph/api/team-post?view=graph-rest-beta&tabs=csharp#example-4-create-a-team-from-group

I already tried a bunch of example from the Microsoft documentation, from the v1.0 and beta one.

My group creation looks like this:

        {
            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,
            };

with the additionnal data being:

           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));

And my team creation look like this:

            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);

So here is my question: What am I doing wrong? Is it a syntax error? Where I can find a documentation about Odata.bind?


回答1:


I resolved my issue with this post

I put a property ODataType = null to every object created.

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);


来源:https://stackoverflow.com/questions/62174014/odata-bind-error-when-creating-a-team-with-microsoft-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!