The mailbox is either inactive, soft-deleted, or is hosted on-premise.

Julien Marpault 26 Reputation points
2024-10-08T11:56:00.2733333+00:00

I have an issue using Graph API for Outlook.

When I use Graph explorer I can request this endpoint:
https://graph.microsoft.com/v1.0/me/mailboxSettings

There is no issue at all.

But when doing the same call in a Blazor Server app with MSAL I get this error:
{"error":{"code":"MailboxNotEnabledForRESTAPI","message":"The mailbox is either inactive, soft-deleted, or is hosted on-premise."}}

Here is the code:

// Program.cs

builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents()
    .AddMicrosoftIdentityConsentHandler();

string[]? scopes = builder.Configuration.GetSection("GraphApi:Scopes").Get<string[]>();

builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration,
       subscribeToOpenIdConnectMiddlewareDiagnosticsEvents: true)
    .EnableTokenAcquisitionToCallDownstreamApi(scopes)
    .AddDownstreamApi("GraphApi", builder.Configuration.GetSection("GraphApi"))
    .AddInMemoryTokenCaches();

builder.Services.AddControllersWithViews()
    .AddMicrosoftIdentityUI();
builder.Services.AddAuthorization(options => { options.FallbackPolicy = options.DefaultPolicy; });
// Home.razor

private async Task UseDownStreamApi(MouseEventArgs arg)
{
    try
    {
        using HttpResponseMessage response = await DownstreamApi.CallApiForUserAsync("GraphApi");
        json = await response.Content.ReadAsStringAsync();
        response.EnsureSuccessStatusCode();
    }
    catch (Exception ex)when(ex is MsalUiRequiredException || ex is MicrosoftIdentityWebChallengeUserException)
    {
        ConsentHandler.HandleException(ex);
    }
    catch (Exception ex)
    {
        json = ex.Message + "\r\n" + json;
        StateHasChanged();
    }
}
Outlook | Windows | Classic Outlook for Windows | For business
Microsoft Security | Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 119.6K Reputation points MVP Volunteer Moderator
    2024-10-08T16:40:45.84+00:00

    How are you authenticating? If using the client credentials flow, there is no logged in user, hence you cannot user /me. Use /user/{userId}/mailboxSettings instead.

    Graph explorer uses delegate permissions, /me works fine therein.

    0 comments No comments

  2. Anonymous
    2024-10-09T02:59:48.78+00:00

    Hello Julien Marpault,

    Thank you for reaching out to Microsoft Support!

    Please check whether your account lacks MS 365 License, as shown below:

    User's image

    You can refer to this case:

    https://learn.microsoft.com/en-us/answers/questions/761931/microsoft-graph-api-throws-the-mailbox-is-either-i

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.