Search code examples
c#microsoft-graph-apiazure-ad-graph-api

Issue with move folder API in Microsoft Graph when Email ID contains "/"


When attempting to move a folder using the following endpoint:

Endpoint: https://graph.microsoft.com/v1.0/me/messages/{EmailId}/move

I'm encountering an error when the EmailId parameter contains a "/" symbol. Despite trying to encode the Email ID, the API continues to return an error.

It's important to note that the API works as expected when the Email ID does not contain a "/" symbol.

I have already attempted to encode the Email ID using URL encoding, but the issue persists. Additionally, escaping the "/" character did not resolve the problem.

The API should be able to move the folder regardless of whether the Email ID contains a "/" symbol.

Following is the error

{"error":{"code":"RequestBroker--ParseUri","message":"Resource not found for the segment 'vUqoAAAIBDAAAANbsh1sqmahFnro5xH'."}}`

Following is the code (it is working fine if emailId didn't has "/"

`using (var httpClient = new HttpClient())
{
    string encodedEmailId = HttpUtility.UrlEncode(emailId);

    var request = new HttpRequestMessage(HttpMethod.Post, $"https://graph.microsoft.com/v1.0/me/messages/{encodedEmailId}/move");
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
    request.Content = new StringContent($"{{\"DestinationId\": \"{folderId}\"}}", Encoding.UTF8, "application/json");

    var response = await httpClient.SendAsync(request);

    string errorMessage = await response.Content.ReadAsStringAsync();
}

Solution

  • If you are using the EWSId from an Outlook Addin you must first convert that to a RESTId (which is base64URL safe) using the Office.context.mailbox.convertToRestId method see https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/use-rest-api for more detail.