Microsoft Teams Graph API - Invalid bind property name owners in request

一世执手 提交于 2021-01-28 06:58:08

问题


I'm currently having major issues with creating teams from the Graph API. I was initially trying to create teams based on groups, however I have found out today that you can now create a team without creating a group first then waiting 15 minutes to then create the team from the following link. This would make things considerably simpler.

https://docs.microsoft.com/en-us/graph/api/team-post?view=graph-rest-1.0

I am using the Microsoft.Graph SDK (v3.12.0 released 26th Aug) so replicated the http call using the SDK as follows.

        var team = new Team
        {
            DisplayName = "My Group Name",
            Description = "My Group Description",
            AdditionalData = new Dictionary<string, object>()
            {
                {"template@odata.bind", "https://graph.microsoft.com/v1.0/teamsTemplates('educationClass')"},
                {"owners@odata.bind", $"[\"https://graph.microsoft.com/v1.0/users('{usersGuid}')\"]"}
            },
        };

        var response = await _graphClient.Teams
            .Request()
            .AddAsync(team);

The code above gives a:

[16:14:01 ERR] An unhandled exception has occurred while executing the request.
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: BadRequest
Message: Invalid bind property name owners in request.

If I remove the line

{"owners@odata.bind", $"[\"https://graph.microsoft.com/v1.0/users('{usersGuid}')\"]"}

from the code I get the following:

ErrorMessage : {"errors":[{"message":"A team owner must be provided when creating a team in application context."}]

Any advice would be greatly appreciated.

Thanks, Nick


回答1:


In v1.0 the owners relationship is not currently present, so you have to use the beta endpoint. POST: https://graph.microsoft.com/beta/teams

with the following body format

{ "template@odata.bind":"https://graph.microsoft.com/beta/teamsTemplates('standard')", "displayName":"Test Team", "description":"Test description", "owners@odata.bind":["https://graph.microsoft.com/v1.0/users/{user guid}"] }

Note: the user guid should also be bare, i.e without the brackets and quotes in your example.



来源:https://stackoverflow.com/questions/63620447/microsoft-teams-graph-api-invalid-bind-property-name-owners-in-request

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