2015-12-06 43 views
-2

我是REST編程的新手,我嘗試使用Microsoft Graph API創建和更新Office 365組,但對於這兩種操作,我都得到一個500 - 內部服務器錯誤響應不太多,以找出什麼是錯的。使用Microsoft Graph創建和更新組返回500 - 內部服務器錯誤

下面是代碼的簡化來創建新組:

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\": \"[email protected]\"," + 
           "\"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 
    } 
} 

我在這裏看到的兩個職位那裏的人設法創建統一的組,所以我猜測它是我找不到的代碼中的東西。其他人是否也經歷過同樣的錯誤?

回答

1

該請求不應將所有組屬性包裝在「組」元素中。正確的請求有效載荷樣本將是:

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

我創建https://github.com/OfficeDev/microsoft-graph-docs/issues/65糾正文檔中使用的樣品。

相關問題