I need to move (some filtered) messages between folders at specified users with Microsoft Graph Api 5.18.
The API documentation give an example with the Messages of the authenticated user (.Me
).
https://learn.microsoft.com/en-us/graph/api/message-move?view=graph-rest-1.0&tabs=csharp
C#
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Me.Messages.Item.Move.MovePostRequestBody
{
DestinationId = "deleteditems",
};
var result = await graphClient.Me.Messages["{message-id}"].Move.PostAsync(requestBody);
It is possible to configure the user id with CLI:
CLI
mgc users messages move post --user-id {user-id} --message-id {message-id} --body '{\
"destinationId": "deleteditems"\
}\
'
How can I define the 'user id' instead of 'Me' in C#?
I'd like to make similar than this (specify the 'user id' with 'ArchiveUser.Id'):
var requestBody = new Microsoft.Graph.Users[ArchiveUser.Id].Messages.Item.Move.MovePostRequestBody
{
DestinationId = "deleteditems",
};
var result2 = await graphClient.Users[ArchiveUser.Id].Messages[item.Id].Move.PostAsync(requestBody);
UPDATE:
What does the correct requestBody2 parameter look like for the following PostAsync parameter? I'd like to use another user id (ArchiveUser.Id) to move his messages.
The class MovePostRequestBody
is in the namespace Microsoft.Graph.Users.Item.Messages.Item.Move
, so create the request body like this:
try
{
var requestBody = new Microsoft.Graph.Users.Item.Messages.Item.Move.MovePostRequestBody
{
DestinationId = "{destination_mailbox_folder_id}",
};
var result2 = await graphClient.Users[ArchiveUser.Id].Messages[item.Id].Move.PostAsync(requestBody);
}
catch (ODataError ex)
{
Console.WriteLine(ex.Error.Code);
Console.WriteLine(ex.Error.Message);
}