Search code examples
c#microsoft-graph-apimicrosoft-plannermicrosoft-graph-plannertasks

MS Graph API Update PlannerTask.ConversationThreadId


I want to update the "ConversationThreadId" field in a PlannerTask.

This is my code:

plannerTask = await graphClient.Planner.Tasks["XXXXXXXXX"].Request().GetAsync();
var eTagId = plannerTask.GetEtag();
plannerTask.ConversationThreadId = "YYYYYYYY";
await graphClient.Planner.Tasks[plannerTask.Id]
    .Request()
    .Header("Prefer", "return=representation")
    .Header("If-Match", eTagId)
    .UpdateAsync(plannerTask);

And it throws this error:

Message: The request is invalid: An unexpected 'StartObject' node was found for property named 'assignedBy' when reading from the JSON reader. A 'PrimitiveValue' node was expected.

What am I doing wrong?

Thank you


Solution

  • The way to get it is:

    plannerTask = await graphClient.Planner.Tasks["XXXXXXXXX"].Request().GetAsync();
    var eTagId = plannerTask.GetEtag();
    var newTask = new PlannerTask {
            ConversationThreadId = "YYYYYYYY"
    };
    await graphClient.Planner.Tasks[plannerTask.Id]
        .Request()
        .Header("Prefer", "return=representation")
        .Header("If-Match", eTagId)
        .UpdateAsync(newTask);
    

    This is because it is not a PUT but a PATCH, and so we only should send the fields that have changed. I was sending the full object, and that was the problem. Now I create newTask and only specify "ConversationThreadId" in it. This way works like a charm for me.