使用 Microsoft Planner 将用户分配给新任务 API
Assigning a user to a new task using Microsoft Planner API
我正在尝试使用 Microsoft Graph API 将用户分配给任务以访问 Planner。 当我不尝试分配某人时我的代码工作正常(通过省略 assignments
部分),但是当我添加分配部分时(following the template here)我收到 BadRequest
错误返回。
{
"error": {
"code": "",
"message": "The request is invalid:\r\nValue cannot be null.\r\nParameter name: qualifiedName",
"innerError": {
"request-id": "...",
"date": "2018-01-30T12:23:59"
}
}
}
public TaskResponse CreateTask(string planId, string bucketId, string title, Dictionary<string, Assignment> assignments = null, DateTime? dueDateTime = null)
{
RestRequest TaskRequest = new RestRequest("planner/tasks", Method.POST)
{
RequestFormat = DataFormat.Json
};
Dictionary<string, object> assignees = new Dictionary<string, object>();
foreach(string assignment in assignments.Keys)
{
assignees.Add(assignment, new
{
});
}
var body = new
{
planId,
bucketId,
title,
assignments = assignees,
dueDateTime
};
TaskRequest.AddParameter("application/json", JsonConvert.SerializeObject(body), "application/json", ParameterType.RequestBody);
IRestResponse TaskResponse = GraphClient.Execute(TaskRequest);
if (!TaskResponse.IsSuccessful)
{
return null;
}
var result = JsonConvert.DeserializeObject<TaskResponse>(TaskResponse.Content);
return result;
}
如果有人知道为什么响应表明我没有提供文档中从未提及的参数,我将不胜感激...
我设法通过使用适当的 class 而不是匿名类型来解决这个问题。通过这样做,我能够用 @odata.type
注释 属性,这作为变量名是不可接受的。
public class NewAssignment
{
[JsonProperty("@odata.type")]
public string ODataType { get; set; }
[JsonProperty("orderHint")]
public string OrderHint { get; set; }
public NewAssignment()
{
ODataType = "#microsoft.graph.plannerAssignment";
OrderHint = " !";
}
}
这让我可以使用以下代码:
Dictionary<string, object> assignees = new Dictionary<string, object>();
foreach (string assignment in assignments.Keys)
{
assignees.Add(assignment, new NewAssignment());
}
var body = new
{
planId,
bucketId,
title,
assignments = assignees,
dueDateTime
};
我正在尝试使用 Microsoft Graph API 将用户分配给任务以访问 Planner。 当我不尝试分配某人时我的代码工作正常(通过省略 assignments
部分),但是当我添加分配部分时(following the template here)我收到 BadRequest
错误返回。
{ "error": { "code": "", "message": "The request is invalid:\r\nValue cannot be null.\r\nParameter name: qualifiedName", "innerError": { "request-id": "...", "date": "2018-01-30T12:23:59" } } }
public TaskResponse CreateTask(string planId, string bucketId, string title, Dictionary<string, Assignment> assignments = null, DateTime? dueDateTime = null)
{
RestRequest TaskRequest = new RestRequest("planner/tasks", Method.POST)
{
RequestFormat = DataFormat.Json
};
Dictionary<string, object> assignees = new Dictionary<string, object>();
foreach(string assignment in assignments.Keys)
{
assignees.Add(assignment, new
{
});
}
var body = new
{
planId,
bucketId,
title,
assignments = assignees,
dueDateTime
};
TaskRequest.AddParameter("application/json", JsonConvert.SerializeObject(body), "application/json", ParameterType.RequestBody);
IRestResponse TaskResponse = GraphClient.Execute(TaskRequest);
if (!TaskResponse.IsSuccessful)
{
return null;
}
var result = JsonConvert.DeserializeObject<TaskResponse>(TaskResponse.Content);
return result;
}
如果有人知道为什么响应表明我没有提供文档中从未提及的参数,我将不胜感激...
我设法通过使用适当的 class 而不是匿名类型来解决这个问题。通过这样做,我能够用 @odata.type
注释 属性,这作为变量名是不可接受的。
public class NewAssignment
{
[JsonProperty("@odata.type")]
public string ODataType { get; set; }
[JsonProperty("orderHint")]
public string OrderHint { get; set; }
public NewAssignment()
{
ODataType = "#microsoft.graph.plannerAssignment";
OrderHint = " !";
}
}
这让我可以使用以下代码:
Dictionary<string, object> assignees = new Dictionary<string, object>();
foreach (string assignment in assignments.Keys)
{
assignees.Add(assignment, new NewAssignment());
}
var body = new
{
planId,
bucketId,
title,
assignments = assignees,
dueDateTime
};