我是 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
}
}
我在这里看到了两个帖子,人们设法创建了统一的组,所以我猜它在代码中我找不到。有没有其他人遇到过同样的错误?