Search code examples
c#.netazuremicrosoft-graph-apimicrosoft-graph-sdks

How to Use MS Graph Beta API for Recalling Sent Emails?


I'm working on implementing a mail recall feature using the MS Graph beta API. To check if the API is functional, I tested the endpoint in Graph Explorer, but encountered an error.

I sent a POST request to:

https://graph.microsoft.com/beta/me/mailFolders/sentitems/messages/AAMkAGUyM2ExYmJiLWMzYWItNGI3Ny1iMDUyLWI0OTIyNzAyODVhMwBGAAAAAABFhmG_ZR5kTpWkPkKe6D2sBwDMA-lWCJwxSZ24LJrXBZC4AAAAAAEJAADaUQ84mKTlTqFYQVwWHYPlAAEcRQSeAAA=/recall

and received the following error:

{
    "error": {
        "code": "BadRequest",
        "message": "Empty Payload. JSON content expected.",
        "innerError": {
            "date": "2024-11-11T06:33:26",
            "request-id": "5d807648-ce8c-4681-a26b-5a13fb3ad2e8",
            "client-request-id": "c7676654-f60e-5c82-1492-a2bbf94c71cb"
        }
    }
}

According to the MS documentation, the API call for recalling a message in the "sent items" folder should work with a POST request like the one I used. Here’s the example provided by the official guide: enter image description here

Here's the links for guide: https://github.com/microsoftgraph/microsoft-graph-docs-contrib/blob/main/api-reference/beta/api/message-recall.md https://learn.microsoft.com/en-us/graph/api/message-recall?view=graph-rest-beta

Also I expected to be able to use code like this, but couldn't find a recall function under Messages in the SDK:

var graphServiceClient = GetGraphServiceClient_Beta();

var result = graphServiceClient.Users[userinfo.UserPrincipalName].MailFolders["sentitems"].Messages[messageId].recall.PostAsync().Result;

My Questions:

  1. How can I successfully use the recall API endpoint in MS Graph?
  2. Is there a way to send a recall request using the MS Graph Beta SDK in .NET? (I have already set up the MS Graph Beta SDK, version 5.86.0.)

Any help or guidance would be appreciated. Thank you!


Solution

  • You are missing {} in the request body.

    POST /beta/me/mailFolders/sentitems/messages/{message_id}/recall
    request body:
    {
    }
    

    Even you if add {} to request body, I can't guarantee that the endpoint will work. It's still the beta version. Sometimes it works fine for me, sometimes it returns the exception

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

    The Graph API .NET SDK for beta still doesn't implement recall method.