Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MicrosoftGraph API fails to mark a message as read

I am using the Microsoft.Graph nuget package (version 1.6.2) and I try to mark an email as read. This is the code:

        msg.IsRead = true;
        await MainPage.GraphServiceClient.Me.Messages[msg.Id].Request().Select("IsRead").UpdateAsync(msg);

From my understanding, the above code should only send the IsRead property to the server for update. However, executing this, sends the whole message object (I have verified this with Fiddler) and you get this response:

{
  "error": {
    "code": "ErrorInvalidPropertyUpdateSentMessage",
    "message": "Update operation is invalid for property of a sent message.",
    "innerError": {
      "request-id": "<A guid here that I wont share>",
      "date": "2017-07-29T21:10:18"
    }
  }
}

Is the code correct, is this a bug, am I missing something or what? Is there a way around this?

like image 361
NoOne Avatar asked Jul 29 '17 21:07

NoOne


Video Answer


1 Answers

I've just encountered your question after being stuck with the same problem my self.

As I came to see after several tries the problem occurs when you try to update (PATCH) fields that aren't allowed to be updated.

In your case and in my case as well, The problem was that we sent the msg object with all of his fields and not only with the patched and modified fields.

Instead of Doing the following:

var msg = await MainPage.GraphServiceClient.Me
    .Messages[imapMessage.MessageId]
    .Request()
    .GetAsync();

msg.IsRead = true;

await MainPage.GraphServiceClient.Me
    .Messages[msg.Id]
    .Request()
    .Select("IsRead")
    .UpdateAsync(msg);

You should only get the IsRead property in the first place,

Update since version 1.9 of the GraphAPI, we need to send only the updated properties without the readonly properties.

await MainPage.GraphServiceClient.Me
    .Messages[msg.Id]
    .Request()
    .Select("IsRead")
    .UpdateAsync(new Message {IsRead = true});

Hoping it will help you if it's still releavent any way.

like image 188
H. Bloch Avatar answered Oct 02 '22 08:10

H. Bloch