【发布时间】:2018-01-30 12:29:00
【问题描述】:
我正在尝试使用 Microsoft Graph API 将用户分配给任务以访问 Planner。 当我不尝试分配某人时,我的代码可以正常工作(通过省略 assignments 部分),但是当我添加分配部分时 (following the template here) 我收到 BadRequest 错误返回。
{ “错误”: { “代码”: ””, "message": "请求无效:\r\n值不能为空。\r\n参数名称:qualifiedName", “内部错误”:{ “请求ID”:“...”, “日期”:“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;
}
如果有人知道为什么响应表明我没有提供文档中从未提及的参数,我将不胜感激...
【问题讨论】:
-
看看网络上实际发生了什么会很有帮助。您能否使用 Fiddler 获取网络跟踪并查看经过的 JSON 有效负载是什么?因为我能够按照 Postman 的记录进行 POST,而不会得到 400。
-
@JasonJohnston 我在示例请求中使用了邮递员并且它有效。然后我从重现我的问题的受让人那里删除了
@odata.type。如何以匿名类型传递此参数名称(它包含@和.等特殊字符)?它需要进入foreach循环中的空对象。
标签: c# microsoft-graph-api restsharp