使用 Microsoft Graph 创建和更新组 returns 500 - 内部服务器错误

Create and update group with Microsoft Graph returns 500 - Internal Server Error

我是 REST 编程的新手,我正在尝试使用 Microsoft Graph API 创建和更新 Office 365 组,但是对于这两个操作,我都收到 500 - Internal Server Error 响应并没有说明太多找出问题所在。

下面是创建新组的代码的简化:

public async Task<Group> CreateGroup()
{
    string accessToken = GetAccessToken(); // method for getting the Graph token

    string newGroup =   "{" +
                            "\"group\": " +
                            "{" +
                                "\"description\": \"description-value\"," +
                                "\"displayName\": \"displayName-value\"," +
                                "\"groupTypes\": [" +
                                   "\"Unified\"" +
                                "]," +
                                "\"mail\": \"somemail@tenantname.com\"," +
                                "\"mailEnabled\": true," +
                                "\"mailNickname\": \"mailNickname-value\"," +
                                "\"securityEnabled\": \"false\"" +
                            "}" +
                        "}";

    using (var client = new HttpClient())
    {
        using (var request = new HttpRequestMessage(HttpMethod.Post, https://graph.microsoft.com/v1.0/groups))
        {
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            request.Content = new StringContent(JsonConvert.SerializeObject(newGroup), Encoding.UTF8, "application/json");

            using (HttpResponseMessage response = await client.SendAsync(request))
            {
                if (response.IsSuccessStatusCode)
                {
                    // parse and return content
                }
                else 
                {
                    // handle error
                }
            }
        }
    }
}

这里是请求和响应消息:

RequestMessage  {Method: POST, RequestUri: 'https://graph.microsoft.com/v1.0/groups', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Authorization: Bearer XXX...
  Content-Type: application/json; charset=utf-8
  Content-Length: 243
}}


ResponseMessage  {StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, 
    Headers:
    {
      Transfer-Encoding: chunked
      request-id: xxxx-...
      client-request-id: xxxx-...
      x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceA","ScaleUnit":"001","Host":"AGSFE_IN_1","ADSiteName":"AMS"}}
      Cache-Control: private
      Date: Sun, 06 Dec 2015 12:51:26 GMT
      Server: Microsoft-IIS/8.5
      X-Powered-By: ASP.NET
      Content-Type: application/json; charset=utf-8
    }
}

我在这里看到了两个帖子,其中人们设法创建了统一的组,所以我猜测它在代码中找不到我找不到的东西。有没有其他人遇到同样的错误?

请求不应将所有组属性包装在 "group" 元素中。正确的请求有效负载示例为:

{  
    "description": "description-value",
    "displayName": "displayName-value",
    "groupTypes": [
      "Unified"
    ],
    "mailEnabled": true,
    "mailNickname": "mailNickname-value",
    "securityEnabled": false
}

我创建了 https://github.com/OfficeDev/microsoft-graph-docs/issues/65 来更正文档中使用的示例。