Reputation: 75
I am starting out in MS Graph. I have below code to pick up all mail messages from Inbox of a specific user. Then I go through each message, process it and set its Subject. When I try to save back message using UpdateAsync I get an 'Id is malformed' exception.
What am I doing wrong?
Thanks
Regards
var inboxMessages = await graphClient
.Users[user.Id]
.MailFolders.Inbox
.Messages
.Request()
.OrderBy("receivedDateTime DESC")
.GetAsync();
foreach(Microsoft.Graph.Message x in inboxMessages) {
//Process message
// ...
x.Subject = "Processed: " + x.Subject
//Save changes to message Subject
await graphClient
.Users[user.Id]
.MailFolders.Inbox
.Messages["{x.Id}"]
.Request()
.UpdateAsync(x);
}
Upvotes: 0
Views: 489
Reputation: 20625
I think you forgot to add $
before "{x.Id}"
when you try to use string interpolation. You do not send id but only string "{x.Id}"
.
It should be
//Save changes to message Subject
await graphClient
.Users[user.Id]
.MailFolders.Inbox
.Messages[$"{x.Id}"]
.Request()
.UpdateAsync(x);
Upvotes: 2