I'm using the Microsoft Graph API to access my Planner tasks from Office 365 and have created an improved front end using Angular and the `@microsoft/microsoft-graph-client. However, I have hit a problem creating new tasks. I can create a new task, but I can't manage to assign it to a user.
My code looks like this:
async addTask(planId: string, bucketId: string, title: string): Promise < Task > {
let postData = { "planId": planId, "bucketId": bucketId, "title": title };
let result = await this.graphClient
.api("/planner/tasks")
.header("Prefer", "return=representation")
.version("beta")
.post(postData);
// works fine up to here and creates the task
let newAssignment = new assignment;
let assignments = `{"${this.userId}": ${newAssignment}}`;
let newTask = await this.graphClient
.api(`/planner/tasks/${result.id}`)
.header("If-Match", result["@odata.etag"])
.header("Prefer", "return=representation")
.patch({ "assignments": assignments });
return newTask;
}
export class assignment {
"@odata.type": string;
orderHint: string;
constructor() {
this["@odata.type"] = "microsoft.graph.plannerAssignment";
this.orderHint = " !";
}
}
The first section works fine and creates the task with nobody assigned, but the second section fails with a 400
error "Property assignments in payload has a value that does not match the schema."
The newAssignments object looks like this:
{
@odata.type: "microsoft.graph.plannerAssignment",
orderHint: " !"
}
I created the assignments class, following the answer to a similar question about C#, previously had just been sending a basic object, like this:
let assignments = `{"${this.userId}": {"@odata.type": "microsoft.graph.plannerAssignment", "orderHint": " !"}}`
but that had also failed with the same error.
One question is whether you amend the assignments property using 'patch' or whether I should be adding an assignment using 'post'. I've tried both and neither work.