I'm trying to assign a user to a task using Microsoft Graph API to access Planner. My code works fine when I'm not trying to assign someone (by leaving out the assignments
section), but when I add the assignments section (following the template here) I get a BadRequest
error back.
{ "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;
}
I'd appreciate if anyone knows why the response is indicating I didn't supply a parameter which is never mentioned in the documentation...
@odata.type
from the assignee which reproduced my problem. How can I pass this parameter name (it contains special characters like@
and.
) in an anonymous type? It needs to go in the empty object in the foreach loop.